smatch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Levon <levon@movementarian.org>
Subject: [PATCH 18/18] sparse: add -Wempty-character-constant
Date: Fri, 23 Nov 2018 13:15:06 +0000	[thread overview]
Message-ID: <E1gQCRX-00068y-CL@movementarian.org> (raw)

Signed-off-by: John Levon <levon@movementarian.org>
---
 cgcc       | 2 +-
 lib.c      | 2 ++
 lib.h      | 1 +
 sparse.1   | 7 +++++++
 tokenize.c | 5 +++--
 5 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/cgcc b/cgcc
index 04869c11..cdb05ab7 100755
--- a/cgcc
+++ b/cgcc
@@ -101,7 +101,7 @@ exit 0;
 
 sub check_only_option {
     my ($arg) = @_;
-    return 1 if $arg =~ /^-W(no-?)?(address-space|big-constants|bitwise|cast-to-as|cast-truncate|context|decl|default-bitfield-sign|designated-init|do-while|enum-mismatch|init-cstring|memcpy-max-count|non-ansi-function-declaration|non-pointer-null|old-initializer|one-bit-signed-bitfield|override-init-all|paren-string|ptr-subtraction-blows|return-void|sizeof-bool|sparse-all|sparse-error|transparent-union|typesign|undef|unknown-attribute)$/;
+    return 1 if $arg =~ /^-W(no-?)?(address-space|big-constants|bitwise|cast-to-as|cast-truncate|context|decl|default-bitfield-sign|designated-init|do-while|empty-character-constant|enum-mismatch|init-cstring|memcpy-max-count|non-ansi-function-declaration|non-pointer-null|old-initializer|one-bit-signed-bitfield|override-init-all|paren-string|ptr-subtraction-blows|return-void|sizeof-bool|sparse-all|sparse-error|transparent-union|typesign|undef|unknown-attribute)$/;
     return 1 if $arg =~ /^-v(no-?)?(entry|dead)$/;
     return 1 if $arg =~ /^-f(dump-linearize|memcpy-max-count)(=\S*)?$/;
     return 0;
diff --git a/lib.c b/lib.c
index 54d10723..7c903a37 100644
--- a/lib.c
+++ b/lib.c
@@ -241,6 +241,7 @@ int Wdesignated_init = 1;
 int Wdo_while = 0;
 int Winit_cstring = 0;
 int Wenum_mismatch = 1;
+int Wempty_character_constant = 1;
 int Wsparse_error = 0;
 int Wmemcpy_max_count = 1;
 int Wnon_ansi_function_declaration = 1;
@@ -544,6 +545,7 @@ static const struct warning {
 	{ "default-bitfield-sign", &Wdefault_bitfield_sign },
 	{ "designated-init", &Wdesignated_init },
 	{ "do-while", &Wdo_while },
+	{ "empty-character-constant", &Wempty_character_constant },
 	{ "enum-mismatch", &Wenum_mismatch },
 	{ "init-cstring", &Winit_cstring },
 	{ "memcpy-max-count", &Wmemcpy_max_count },
diff --git a/lib.h b/lib.h
index cc87da3a..8509dbbf 100644
--- a/lib.h
+++ b/lib.h
@@ -128,6 +128,7 @@ extern int Wdefault_bitfield_sign;
 extern int Wdesignated_init;
 extern int Wdo_while;
 extern int Wenum_mismatch;
+extern int Wempty_character_constant;
 extern int Wsparse_error;
 extern int Winit_cstring;
 extern int Wmemcpy_max_count;
diff --git a/sparse.1 b/sparse.1
index cc72ad63..718bae6f 100644
--- a/sparse.1
+++ b/sparse.1
@@ -208,6 +208,13 @@ Sparse issues these warnings by default.  To turn them off, use
 \fB\-Wno\-enum\-mismatch\fR.
 .
 .TP
+.B \-Wempty\-character\-constant
+Warn about a constant such as ''.
+
+Sparse issues these warnings by default.  To turn them off, use
+\fB\-Wno\-empty\-character\-constant\fR.
+.
+.TP
 .B \-Winit\-cstring
 Warn about initialization of a char array with a too long constant C string.
 
diff --git a/tokenize.c b/tokenize.c
index ff5b1367..12c1f43e 100644
--- a/tokenize.c
+++ b/tokenize.c
@@ -630,8 +630,9 @@ static int eat_string(int next, stream_t *stream, enum token_type type)
 	}
 	if (delim == '\'' && len <= 4) {
 		if (len == 0) {
-			sparse_error(stream_pos(stream),
-				"empty character constant");
+			if (Wempty_character_constant)
+				sparse_error(stream_pos(stream),
+					"empty character constant");
 			return nextchar(stream);
 		}
 		token_type(token) = type + len;
-- 
2.14.1

                 reply	other threads:[~2018-11-24  1:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=E1gQCRX-00068y-CL@movementarian.org \
    --to=levon@movementarian.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 read-only IMAP folder(s) and NNTP newsgroup(s).