0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-10-10 00:25:06 -04:00

quote.c: let nasm_skip_string() return NULL for a non-string

Returning NULL makes more sense than returning the initial pointer
(the only other sensible alternative would be to return a pointer the
final null character.)

This currently can't happen, as all callers to nasm_skip_string()
currently explicitly tests for an initial quote.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin
2019-06-06 16:29:52 -07:00
parent 5282cea85b
commit 4d7bf79ed7

View File

@@ -484,7 +484,7 @@ size_t nasm_unquote_cstr(char *str, char **ep)
/*
* Find the end of a quoted string; returns the pointer to the terminating
* character (either the ending quote or the null character, if unterminated.)
* If the input is not a quoted string,
* If the input is not a quoted string, return NULL.
*/
char *nasm_skip_string(const char *str)
{
@@ -499,11 +499,15 @@ char *nasm_skip_string(const char *str)
bq = str[0];
p = str+1;
if (bq == '\'' || bq == '\"') {
switch (bq) {
case '\'':
case '\"':
/* '...' or "..." string */
while ((c = *p++) && (c != bq))
;
} else if (bq == '`') {
break;
case '`':
/* `...` string */
state = st_start;
while (state != st_done) {
@@ -537,6 +541,11 @@ char *nasm_skip_string(const char *str)
panic();
}
}
break;
default:
/* Not a string at all... */
return NULL;
}
return (char *)p - 1;
}