[PATCH 14/18] Track sparse-level warnings and errors too, and respect them in smatch's exit code.

John Levon <[email protected]>
Newsgroups org.kernel.vger.smatch
Message-ID <[email protected]>
Signed-off-by: John Levon <[email protected]>
---
 lib.c    | 11 +++++++----
 lib.h    |  2 ++
 smatch.c |  2 +-
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/lib.c b/lib.c
index a82408e8..54d10723 100644
--- a/lib.c
+++ b/lib.c
@@ -47,6 +47,9 @@
 
 static const char *progname;
 
+int sparse_errors = 0;
+int sparse_warnings = 0;
+
 int verbose, optimize, optimize_size, preprocessing;
 int die_if_error = 0;
 int parse_error;
@@ -133,14 +136,12 @@ void info(struct position pos, const char * fmt, ...)
 
 static void do_error(struct position pos, const char * fmt, va_list args)
 {
-	static int errors = 0;
-
 	parse_error = 1;
         die_if_error = 1;
 	show_info = 1;
 	/* Shut up warnings after an error */
 	has_error |= ERROR_CURR_PHASE;
-	if (errors > 100) {
+	if (sparse_errors > 100) {
 		static int once = 0;
 		show_info = 0;
 		if (once)
@@ -150,7 +151,7 @@ static void do_error(struct position pos, const char * fmt, va_list args)
 	}
 
 	do_warn("error: ", pos, fmt, args);
-	errors++;
+	sparse_errors++;
 }	
 
 void warning(struct position pos, const char * fmt, ...)
@@ -169,6 +170,8 @@ void warning(struct position pos, const char * fmt, ...)
 		return;
 	}
 
+	sparse_warnings++;
+
 	if (!--max_warnings) {
 		show_info = 0;
 		fmt = "too many warnings";
diff --git a/lib.h b/lib.h
index bfb35466..cc87da3a 100644
--- a/lib.h
+++ b/lib.h
@@ -45,6 +45,8 @@ extern int die_if_error;
 extern int parse_error;
 extern int repeat_phase, merge_phi_sources;
 extern int gcc_major, gcc_minor, gcc_patchlevel;
+extern int sparse_warnings;
+extern int sparse_errors;
 
 extern unsigned int hexval(unsigned int c);
 
diff --git a/smatch.c b/smatch.c
index 2ccf8d76..c00e75d9 100644
--- a/smatch.c
+++ b/smatch.c
@@ -359,7 +359,7 @@ int main(int argc, char **argv)
 	smatch(argc, argv);
 	free_string(data_dir);
 
-	if (sm_nr_errors > 0)
+	if (sm_nr_errors > 0 || sparse_errors > 0)
 		return 1;
 	if (sm_nr_checks > 0 && option_fatal_checks)
 		return 1;
-- 
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.