From 3b54ee2f16c6118db4e7164d81a77be4fc3300e6 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Wed, 29 Jul 2020 21:02:17 +0200 Subject: fix stream_prev() for invalid (negative) stream Now that the parent stream is stored as a position, the validity of a stream can't anymore be tested by checking if its number is non-negative because inside a struct position stream number are stored as an unsigned (and changing it to signed would halve the maximum number of stream). So, add a check against input_stream_nr before returning the previous stream. Fixes: 4c6cbe557c48205f9b3d2aae4c166cd66446b240 Signed-off-by: Luc Van Oostenryck --- tokenize.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tokenize.c b/tokenize.c index d68fbcd8..ca842f52 100644 --- a/tokenize.c +++ b/tokenize.c @@ -66,7 +66,10 @@ int stream_prev(int stream) { if (stream < 0 || stream > input_stream_nr) return -1; - return input_streams[stream].pos.stream; + stream = input_streams[stream].pos.stream; + if (stream > input_stream_nr) + return -1; + return stream; } static struct position stream_pos(stream_t *stream) -- cgit 1.2.3-korg From 2f255a14665d9b584a3de528242bb948ff63f977 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Thu, 30 Jul 2020 00:02:44 +0200 Subject: fix diagnostic source path from command line Now, diagnostic messages are prepended with the source path. But if the problem comes from a file included directly from the command line like: sparse -include some-buggy-file.c the prepended message will be: (null): note: in included file ... because there isn't a source path yet. So, initialize the source path to "command-line". Signed-off-by: Luc Van Oostenryck --- lib.c | 2 ++ validation/preprocessor/bad-cmdline-include.c | 11 +++++++++++ 2 files changed, 13 insertions(+) create mode 100644 validation/preprocessor/bad-cmdline-include.c diff --git a/lib.c b/lib.c index 2b600fee..4bc5cd02 100644 --- a/lib.c +++ b/lib.c @@ -383,6 +383,8 @@ struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list char **args; struct symbol_list *list; + base_filename = "command-line"; + // Initialize symbol stream first, so that we can add defines etc init_symbols(); diff --git a/validation/preprocessor/bad-cmdline-include.c b/validation/preprocessor/bad-cmdline-include.c new file mode 100644 index 00000000..e4ee03f4 --- /dev/null +++ b/validation/preprocessor/bad-cmdline-include.c @@ -0,0 +1,11 @@ +#error some random error + +/* + * check-name: bad-cmdline-include + * check-command: sparse -include $file + * + * check-error-start +command-line: note: in included file (through builtin): +preprocessor/bad-cmdline-include.c:1:2: error: some random error + * check-error-end + */ -- cgit 1.2.3-korg