bug-grep
[Top][All Lists]
Advanced

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

avoiding warnings: one last patch


From: Jim Meyering
Subject: avoiding warnings: one last patch
Date: Tue, 23 Mar 2010 10:05:19 +0100

Testing with other versions of gcc, I encountered these
warnings from gcc-4.1.2 (mapped to error with -Werror):

    cc1: warnings being treated as errors
    dfa.c: In function 'lex':
    dfa.c:467: warning: 'wc' may be used uninitialized in this function
    dfa.c:463: warning: 'c' may be used uninitialized in this function
    dfa.c:467: warning: 'wc2' may be used uninitialized in this function
    dfa.c:467: warning: 'wc1' may be used uninitialized in this function
    dfa.c:463: warning: 'c2' may be used uninitialized in this function
    make[2]: *** [dfa.o] Error 1

And in a way, they seem legitimate, assuming that older gcc doesn't
recognize "error (EXIT_TROUBLE, ..." as something that resolves to
exit (EXIT_TROUBLE).

The clang static analyzer makes the same "mistake" in reporting a
false-positive "used-uninitialized" warning, so I wrote the following
patch, which is sufficient to teach both clang and gcc-4.1.2 enough
that they no longer give FP warnings.

It's risky to do *anything* this close to release, but I've confirmed
this solves the problem and everything still builds on numerous systems,
so unless someone points out a problem very soon, I'll push it and it
will be included in grep-2.6.


>From ce050df795d2dd825e866d368423b886d6eac4ef Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Tue, 23 Mar 2010 09:35:45 +0100
Subject: [PATCH] build: avoid warnings: tell gcc and clang that dfaerror never 
returns

* src/dfa.h (__attribute__): Define.
(dfaerror): Declare with the "noreturn" attribute.
* src/dfasearch.c (dfaerror): Add an unreachable use of abort.
---
 src/dfa.h       |    6 +++++-
 src/dfasearch.c |    4 ++++
 2 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/src/dfa.h b/src/dfa.h
index 79e9fd0..1c85207 100644
--- a/src/dfa.h
+++ b/src/dfa.h
@@ -39,6 +39,10 @@
 /* Number of ints required to hold a bit for every character. */
 #define CHARCLASS_INTS ((NOTCHAR + INTBITS - 1) / INTBITS)

+#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6) || __STRICT_ANSI__
+# define __attribute__(x)
+#endif
+
 /* Sets of unsigned characters are stored as bit vectors in arrays of ints. */
 typedef int charclass[CHARCLASS_INTS];

@@ -429,4 +433,4 @@ extern void dfastate (int, struct dfa *, int []);
 /* dfaerror() is called by the regexp routines whenever an error occurs.  It
    takes a single argument, a NUL-terminated string describing the error.
    The user must supply a dfaerror.  */
-extern void dfaerror (const char *);
+extern void dfaerror (const char *) __attribute__ ((noreturn));
diff --git a/src/dfasearch.c b/src/dfasearch.c
index 996effd..a43f822 100644
--- a/src/dfasearch.c
+++ b/src/dfasearch.c
@@ -49,6 +49,10 @@ void
 dfaerror (char const *mesg)
 {
   error (EXIT_TROUBLE, 0, "%s", mesg);
+
+  /* notreached */
+  /* Tell static analyzers that this function does not return.  */
+  abort ();
 }

 /* Number of compiled fixed strings known to exactly match the regexp.
--
1.7.0.3.435.g097f4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]