提交 921aec17 编写于 作者: A antirez

sdssplitargs(): now returns NULL only on error.

An empty input string also resulted into the function returning NULL
making it harder for the caller to distinguish between error and empty
string without checking the original input string length.
上级 e1742903
......@@ -480,6 +480,11 @@ int hex_digit_to_int(char c) {
*
* Note that sdscatrepr() is able to convert back a string into
* a quoted string in the same format sdssplitargs() is able to parse.
*
* The function returns the allocated tokens on success, even when the
* input string is empty, or NULL if the input contains unbalanced
* quotes or closed quotes followed by non space characters
* as in: "foo"bar or "foo'
*/
sds *sdssplitargs(const char *line, int *argc) {
const char *p = line;
......@@ -576,6 +581,9 @@ sds *sdssplitargs(const char *line, int *argc) {
(*argc)++;
current = NULL;
} else {
/* Even on empty input string returns something not NULL that
* can be freed by sdssplitargs_free. */
if (vector == NULL) vector = zmalloc(sizeof(void*));
return vector;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册