[PATCH 18/18] sparse: add -Wempty-character-constant

John Levon <[email protected]>
Newsgroups org.kernel.vger.smatch
Message-ID <[email protected]>
Signed-off-by: John Levon <[email protected]>
---
 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.