bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] useless-if-before-free: Check for nullptr.


From: Collin Funk
Subject: [PATCH] useless-if-before-free: Check for nullptr.
Date: Sun, 16 Jun 2024 20:52:20 -0700

* build-aux/useless-if-before-free (is_NULL): Add nullptr to the
condition.
(foo): Add nullptr to the regular expressions.
---
 ChangeLog                        | 7 +++++++
 build-aux/useless-if-before-free | 8 ++++----
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 52c07bde4f..7cff764b38 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-06-16  Collin Funk  <collin.funk1@gmail.com>
+
+       useless-if-before-free: Check for nullptr.
+       * build-aux/useless-if-before-free (is_NULL): Add nullptr to the
+       condition.
+       (foo): Add nullptr to the regular expressions.
+
 2024-06-16  Paul Eggert  <eggert@cs.ucla.edu>
 
        nstrftime: omit never-used code
diff --git a/build-aux/useless-if-before-free b/build-aux/useless-if-before-free
index ac9c890170..968e53062c 100755
--- a/build-aux/useless-if-before-free
+++ b/build-aux/useless-if-before-free
@@ -36,7 +36,7 @@
 eval 'exec perl -wSx "$0" "$@"'
      if 0;
 
-my $VERSION = '2022-01-27 18:51'; # UTC
+my $VERSION = '2024-06-17 03:44'; # 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
@@ -106,7 +106,7 @@ EOF
 sub is_NULL ($)
 {
   my ($expr) = @_;
-  return ($expr eq 'NULL' || $expr eq '0');
+  return ($expr eq 'NULL' || $expr eq 'nullptr' || $expr eq '0');
 }
 
 {
@@ -211,7 +211,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*\)\s*;)/$2/s'
+   
's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*(?:0|NULL|nullptr))?\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;
@@ -220,7 +220,7 @@ free=kfree
 git grep -l -z "$free *(" \
   | xargs -0 useless-if-before-free -l --name="$free" \
   | xargs -0 perl -0777 -pi -e \
-     
's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*(?:0|NULL))?\s*\)\s*\{\s*('"$free"'\s*\((?:\s*\([^)]+\))?\s*\1\s*\);)\s*\}[^\n]*$/$2/gms'
+     
's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*(?:0|NULL|nullptr))?\s*\)\s*\{\s*('"$free"'\s*\((?:\s*\([^)]+\))?\s*\1\s*\);)\s*\}[^\n]*$/$2/gms'
 
 Be careful that the result of the above transformation is valid.
 If the matched string is followed by "else", then obviously, it won't be.
-- 
2.45.2




reply via email to

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