Powered by Linux
[PATCH 04/12] sparse: add -Wempty-character-constant — Semantic Matching Tool

[PATCH 04/12] sparse: add -Wempty-character-constant

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

 



Signed-off-by: John Levon <levon@xxxxxxxxxxxxxxxxx>
---
 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 04869c1..cdb05ab 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 ed7d9ed..0f3a05a 100644
--- a/lib.c
+++ b/lib.c
@@ -236,6 +236,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;
@@ -534,6 +535,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 bfb3546..d5693ed 100644
--- a/lib.h
+++ b/lib.h
@@ -126,6 +126,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 cc72ad6..718bae6 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 ff5b136..12c1f43 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;
-- 
1.8.3.1




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux