linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 2/6] fix: accept 'sparse -D M...'
Date: Wed, 13 Dec 2017 18:15:27 +0100	[thread overview]
Message-ID: <20171213171531.43707-3-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20171213171531.43707-1-luc.vanoostenryck@gmail.com>

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>
---
 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


  parent reply	other threads:[~2017-12-13 17:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-13 17:15 [PATCH 0/6] whitespace & '-D' option Luc Van Oostenryck
2017-12-13 17:15 ` [PATCH 1/6] add testcase for 'sparse -D M...' Luc Van Oostenryck
2017-12-13 17:15 ` Luc Van Oostenryck [this message]
2017-12-13 17:15 ` [PATCH 3/6] testsuite: add test case for quoting of command's arguments Luc Van Oostenryck
2017-12-13 17:15 ` [PATCH 4/6] testsuite: respect command line's quotes & whitespaces Luc Van Oostenryck
2017-12-13 17:15 ` [PATCH 5/6] add test case for space within command line Luc Van Oostenryck
2017-12-13 17:15 ` [PATCH 6/6] fix: spaces in macro definition on the " Luc Van Oostenryck
2017-12-15  6:15 ` [PATCH 0/6] whitespace & '-D' option Christopher Li
2017-12-17 14:58   ` Luc Van Oostenryck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171213171531.43707-3-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).