Sparse allows (but warns about) a bare newline (not preceded by a backslash) inside a string. Since this is invalid C, it's probable that a terminating '"' is missing just before the newline. In this case, allowing the newline implies accepting the following characters until the next '"' is found, which is most case creates a lot of irrelevant warnings. Change this by disallowing newlines inside strings, exactly like already done for character constants. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- tokenize.c | 6 +++--- validation/check_byte_count-ice.c | 2 +- validation/preprocessor/missing-delim.c | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 validation/preprocessor/missing-delim.c diff --git a/tokenize.c b/tokenize.c index e98684ec5..ef298cb48 100644 --- a/tokenize.c +++ b/tokenize.c @@ -580,9 +580,9 @@ static int eat_string(int next, stream_t *stream, enum token_type type) len++; if (next == '\n') { warning(stream_pos(stream), - "Newline in string or character constant"); - if (delim == '\'') /* assume it's lost ' */ - break; + "missing delimitator %c", delim); + /* assume delimiter is lost */ + break; } if (next == EOF) { warning(stream_pos(stream), diff --git a/validation/check_byte_count-ice.c b/validation/check_byte_count-ice.c index dae40c676..16d352921 100644 --- a/validation/check_byte_count-ice.c +++ b/validation/check_byte_count-ice.c @@ -8,7 +8,7 @@ static void foo(void *a) * check-name: Segfault in check_byte_count after syntax error * * check-error-start -check_byte_count-ice.c:6:0: warning: Newline in string or character constant +check_byte_count-ice.c:6:0: warning: missing delimitator ' check_byte_count-ice.c:5:23: warning: multi-character character constant check_byte_count-ice.c:6:1: error: Expected ) in function call check_byte_count-ice.c:6:1: error: got } diff --git a/validation/preprocessor/missing-delim.c b/validation/preprocessor/missing-delim.c new file mode 100644 index 000000000..eb3d42ab9 --- /dev/null +++ b/validation/preprocessor/missing-delim.c @@ -0,0 +1,17 @@ +static int c = 'a; + +static char s[] = "abc; +static char t[] = "xyz"; + +extern void foo(void); + +/* + * check-name: missing-delim + * check-command: sparse -E $file + * check-output-ignore + * + * check-error-start +preprocessor/missing-delim.c:2:0: warning: missing delimitator ' +preprocessor/missing-delim.c:4:0: warning: missing delimitator " + * check-error-end + */ -- 2.19.0