bug-gnulib
[Top][All Lists]
Advanced

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

[PATCHv2] maint.mk: improve sc_prohibit_strcmp regex


From: Eric Blake
Subject: [PATCHv2] maint.mk: improve sc_prohibit_strcmp regex
Date: Thu, 6 Jan 2011 15:51:22 -0700

* top/maint.mk (sc_prohibit_strcmp): Detect strcmp()!=0, as
documented.  Also, detect strcmp((expr),expr) == 0.  Exempt the
definition of STRNEQ.

Signed-off-by: Eric Blake <address@hidden>
---

> I'm currently testing this on several projects (m4, coreutils,
> and libvirt), if the looser regex doesn't turn up any false
> positives, (or if I get list consensus before I finish testing),
> I'll go ahead and push.

Found 1 false positive on libvirt:

# define STRNEQ(a,b) (strcmp(a,b) != 0)

and 1 real bug (previously a false negative) on m4:

    if (strcmp (ARG (0), ARG (1)) == 0)

and no change in behavior on coreutils.

The false negative is easy enough to avoid, by using:

  | grep -vE ':# *define STRN\?EQ\('

and updating the recommendation to mention STREQ or STRNEQ (coreutils
uses !STREQ instead of STRNEQ, but it is a pretty trivial conversion
between the two styles according to the project preferences).

 ChangeLog    |    5 +++++
 top/maint.mk |    6 +++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2816f95..1b7a923 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2011-01-06  Eric Blake  <address@hidden>

+       maint.mk: improve sc_prohibit_strcmp regex
+       * top/maint.mk (sc_prohibit_strcmp): Detect strcmp()!=0, as
+       documented.  Also, detect strcmp((expr),expr) == 0.  Exempt the
+       definition of STRNEQ.
+
        signal: work around Haiku issue with SIGBUS
        * lib/siglist.h: Add comment.
        * lib/sig2str.c (numname_table): Swap SIGBUS order, to match
diff --git a/top/maint.mk b/top/maint.mk
index f892304..5906b0d 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -292,10 +292,10 @@ sc_prohibit_atoi_atof:

 # Use STREQ rather than comparing strcmp == 0, or != 0.
 sc_prohibit_strcmp:
-       @grep -nE '! *str''cmp *\(|\<str''cmp *\([^)]+\) *=='           \
+       @grep -nE '! *str''cmp *\(|\<str''cmp *\(.+\) *[!=]='   \
            $$($(VC_LIST_EXCEPT))                                       \
-         | grep -vE ':# *define STREQ\(' &&                            \
-         { echo '$(ME): use STREQ in place of the above uses of str''cmp' \
+         | grep -vE ':# *define STRN\?EQ\(' &&                         \
+         { echo '$(ME): replace str''cmp calls above with STREQ/STRNEQ' \
                1>&2; exit 1; } || :

 # Pass EXIT_*, not number, to usage, exit, and error (when exiting)
-- 
1.7.3.4




reply via email to

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