bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] useless-if-before-free: avoid false-positive


From: Jim Meyering
Subject: [PATCH] useless-if-before-free: avoid false-positive
Date: Wed, 20 Apr 2011 15:47:11 +0200

FYI, while fixing gcc's useless-if-before-free,
I learned of this bug:

From 67ce653056298965788199437efe1e0f6c06eec5 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Wed, 20 Apr 2011 15:44:54 +0200
Subject: [PATCH] useless-if-before-free: avoid false-positive

* build-aux/useless-if-before-free: Adjust regexp for the non-brace
disjunct so that it too requires a terminating ";".  Without that,
this script would identify as useless one statement from gcc that
was not:
  if (aligned_ptr)
    free (((void **) aligned_ptr) [-1]);
---
 ChangeLog                        |   10 ++++++++++
 build-aux/useless-if-before-free |    6 +++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1787060..5081b45 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-04-20  Jim Meyering  <address@hidden>
+
+       useless-if-before-free: avoid false-positive
+       * build-aux/useless-if-before-free: Adjust regexp for the non-brace
+       disjunct so that it too requires a terminating ";".  Without that,
+       this script would identify as useless one statement from gcc that
+       was not:
+         if (aligned_ptr)
+           free (((void **) aligned_ptr) [-1]);
+
 2011-04-20  Giuseppe Scrivano  <address@hidden>

        doc: update users.txt.
diff --git a/build-aux/useless-if-before-free b/build-aux/useless-if-before-free
index a6c228b..b8f5a26 100755
--- a/build-aux/useless-if-before-free
+++ b/build-aux/useless-if-before-free
@@ -4,7 +4,7 @@ eval '(exit $?0)' && eval 'exec perl -wST "$0" ${1+"$@"}'
 # Detect instances of "if (p) free (p);".
 # Likewise "if (p != 0)", "if (0 != p)", or with NULL; and with braces.

-my $VERSION = '2011-01-09 01:39'; # UTC
+my $VERSION = '2011-04-20 13:43'; # UTC
 # The definition above must lie within the first 8 lines in order
 # for the Emacs time-stamp write hook (at end) to update it.
 # If you change this file with Emacs, please let the write hook
@@ -132,7 +132,7 @@ sub is_NULL ($)
           while ($line =~
               /\b(if\s*\(\s*([^)]+?)(?:\s*!=\s*([^)]+?))?\s*\)
               #  1          2                  3
-               (?:   \s*$regexp\s*\((?:\s*\([^)]+\))?\s*([^)]+)\)|
+               (?:   \s*$regexp\s*\((?:\s*\([^)]+\))?\s*([^)]+)\)\s*;|
                 
\s*\{\s*$regexp\s*\((?:\s*\([^)]+\))?\s*([^)]+)\)\s*;\s*\}))/sxg)
             {
               my $all = $1;
@@ -179,7 +179,7 @@ free=xfree
 git grep -l -z "$free *(" \
   | xargs -0 useless-if-before-free -l --name="$free" \
   | xargs -0 perl -0x3b -pi -e \
-   
's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*(?:0|NULL))?\s*\)\s+('"$free"'\s*\((?:\s*\([^)]+\))?\s*\1\s*\))/$2/s'
+   
's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*(?:0|NULL))?\s*\)\s+('"$free"'\s*\((?:\s*\([^)]+\))?\s*\1\s*\)\s*;)/$2/s'

 # Use the following to remove redundant uses of kfree inside braces.
 # Note that -0777 puts perl in slurp-whole-file mode;
--
1.7.5.rc2.295.g19c42



reply via email to

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