bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] maint.mk: improve sc_prohibit_strcmp regex


From: Eric Blake
Subject: [PATCH] maint.mk: improve sc_prohibit_strcmp regex
Date: Thu, 6 Jan 2011 14:39:23 -0700

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

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

This was found indirectly via a false negative on libvirt, which
had copied the regex over to a cfg.mk rule for strncmp/STRPREFIX.
The regex was too tight, and missed that 'strncmp(env,"LD_",3)!=0'
should have been replaced with '!STRPREFIX(env,"LD_")'.

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.

An example false positive from the looser regex would be:

int
qsort_callback (const void *a, const void *b)
{
  const char *stra = a;
  const char *strb = b;
  return strcmp (a, ((*b) == ':' ? "" : b));
}

But it seems unlikely to have something that contrived in real code.

 ChangeLog    |    4 ++++
 top/maint.mk |    2 +-
 2 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2816f95..1b7a923 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 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.
+
        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..3d05d99 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -292,7 +292,7 @@ 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' \
-- 
1.7.3.4




reply via email to

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