summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-12-07 17:20:10 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-12-09 16:14:16 +0100
commitb7f05bc01b1b61359e3f7e41b504e763e5a9880b (patch)
tree0db2f6f40ad5ceea42bbf5bc2686fe10108ea5df
parent485700db8ffc3fe0cba6cd8464eef020da18bc53 (diff)
downloadsparse-b7f05bc01b1b61359e3f7e41b504e763e5a9880b.tar.gz
don't allow newlines inside string literals
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@gmail.com>
-rw-r--r--tokenize.c6
-rw-r--r--validation/check_byte_count-ice.c2
-rw-r--r--validation/preprocessor/missing-delim.c5
3 files changed, 6 insertions, 7 deletions
diff --git a/tokenize.c b/tokenize.c
index e98684ec..0d17d42d 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 terminating %c character", 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 dae40c67..88783865 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 terminating ' character
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
index 3763520b..60957fb9 100644
--- a/validation/preprocessor/missing-delim.c
+++ b/validation/preprocessor/missing-delim.c
@@ -9,10 +9,9 @@ extern void foo(void);
* check-name: missing-delim
* check-command: sparse -E $file
* check-output-ignore
- * check-known-to-fail
*
* check-error-start
-preprocessor/missing-delim.c:2:0: warning: missing delimitator '
-preprocessor/missing-delim.c:4:0: warning: missing delimitator "
+preprocessor/missing-delim.c:2:0: warning: missing terminating ' character
+preprocessor/missing-delim.c:4:0: warning: missing terminating " character
* check-error-end
*/