aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-12-13 11:36:04 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-12-13 12:01:52 +0100
commit7f1011b311e9329f53d73f88de495ea64071eb77 (patch)
tree74563d6c789fd9564879133524e5e35d0d1df372
parent35d5258088461b392719433852f54ef28242c2d7 (diff)
downloadsparse-dev-7f1011b311e9329f53d73f88de495ea64071eb77.tar.gz
fix: accept 'sparse -D M...'
Till now, sparse was unneedlessly strict in what it accepted in '-D' options. More specifically, it doesn't accept: 1) separated '-D' and the macro definition, like: sparse -D MACRO[=definition] ... 2) a space between the '-D' and the macro name, like: sparse '-D MACRO[=definition] ... Case 1) is clearly accepted by GCC, clang and should be accepted for a POSIX's c99. Case 2's status is less clear but is also accepted by GCC and clang (leaving any validation to the corresponding internal #define). Fix this by accepting separated command line argument for '-D' and the macro (and removing the check that rejected the macro part if it started with a space). Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--lib.c12
-rw-r--r--validation/preprocessor/cli-D-arg.c1
2 files changed, 8 insertions, 5 deletions
diff --git a/lib.c b/lib.c
index 037206f7..236d58fc 100644
--- a/lib.c
+++ b/lib.c
@@ -323,12 +323,16 @@ static char **handle_switch_D(char *arg, char **next)
const char *name = arg + 1;
const char *value = "1";
- if (!*name || isspace((unsigned char)*name))
- die("argument to `-D' is missing");
+ if (!*name) {
+ arg = *++next;
+ if (!arg)
+ die("argument to `-D' is missing");
+ name = arg;
+ }
- for (;;) {
+ for (;;arg++) {
char c;
- c = *++arg;
+ c = *arg;
if (!c)
break;
if (isspace((unsigned char)c) || c == '=') {
diff --git a/validation/preprocessor/cli-D-arg.c b/validation/preprocessor/cli-D-arg.c
index b098e98b..03c5bac3 100644
--- a/validation/preprocessor/cli-D-arg.c
+++ b/validation/preprocessor/cli-D-arg.c
@@ -3,7 +3,6 @@ B
/*
* check-name: cli: -D MACRO
* check-command: sparse -E -D A -D B=abc $file
- * check-known-to-fail
*
* check-output-start