[PATCH 2/6] fix: accept 'sparse -D M...'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 lib.c                               | 12 ++++++++----
 validation/preprocessor/cli-D-arg.c |  1 -
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib.c b/lib.c
index 037206f72..236d58fc9 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 b098e98bd..03c5bac34 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
 
-- 
2.15.0

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux