} state = START;
assert(p);
- assert(*p);
assert(ret);
+ /* Bail early if called after last value or with no input */
+ if (!*p)
+ goto finish_force_terminate;
+
/* Parses the first word of a string, and returns it in
* *ret. Removes all quotes in the process. When parsing fails
* (because of an uneven number of quotes or similar), leaves
case START:
if (c == 0)
- goto finish;
+ goto finish_force_terminate;
else if (strchr(WHITESPACE, c))
break;
case VALUE:
if (c == 0)
- goto finish;
+ goto finish_force_terminate;
else if (c == '\'') {
if (!GREEDY_REALLOC(s, allocated, sz+1))
return -ENOMEM;
case SINGLE_QUOTE:
if (c == 0) {
if (flags & UNQUOTE_RELAX)
- goto finish;
+ goto finish_force_terminate;
return -EINVAL;
} else if (c == '\'')
state = VALUE;
* mode, UNQUOTE_CUNESCAP_RELAX mode does not allow them.
*/
s[sz++] = '\\';
- goto finish;
+ goto finish_force_terminate;
}
if (flags & UNQUOTE_RELAX)
- goto finish;
+ goto finish_force_terminate;
return -EINVAL;
}
(*p) ++;
}
+finish_force_terminate:
+ *p = NULL;
finish:
if (!s) {
+ *p = NULL;
*ret = NULL;
return 0;
}