]> xenbits.xensource.com Git - libvirt.git/commitdiff
maint: tighten strncmp syntax check
authorEric Blake <eblake@redhat.com>
Wed, 17 Nov 2010 23:41:31 +0000 (16:41 -0700)
committerEric Blake <eblake@redhat.com>
Thu, 18 Nov 2010 19:21:58 +0000 (12:21 -0700)
Using 'int ret = strcmp(a, b)' in a qsort function is a valid use of
str[n]cmp that should _not_ be turned to STREQ, but it was falling
foul of our specific syntax-check.  Meanwhile, gnulib's maint.mk
already has a tighter bound for strcmp, so we can copy that regex and
just check for strncmp, which results in fewer false positives that
require exceptions.

* cfg.mk (sc_prohibit_strcmp_and_strncmp): Rename...
(sc_prohibit_strncmp): ...to this, and tighten, to mirror
maint.mk's sc_prohibit_strcmp's better regex.
* Makefile.am (syntax_check_exceptions): Update exception rule.
* .x-sc_prohibit_strcmp_and_strncmp: Rename...
* .x-sc_prohibit_strncmp: ...and trim.

.x-sc_prohibit_strcmp_and_strncmp [deleted file]
.x-sc_prohibit_strncmp [new file with mode: 0644]
Makefile.am
cfg.mk

diff --git a/.x-sc_prohibit_strcmp_and_strncmp b/.x-sc_prohibit_strcmp_and_strncmp
deleted file mode 100644 (file)
index 77c3ee6..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-^gnulib/
-^ChangeLog-old$
-^docs/
-^examples/domain-events/events-c/event-test\.c$
-^src/internal\.h$
-^src/lxc/lxc_container\.c$
-^src/node_device/node_device_devkit\.c$
-^src/node_device/node_device_hal\.c$
-^src/storage/parthelper\.c$
diff --git a/.x-sc_prohibit_strncmp b/.x-sc_prohibit_strncmp
new file mode 100644 (file)
index 0000000..8be2055
--- /dev/null
@@ -0,0 +1 @@
+^src/internal\.h$
index e88814467da66af2db8f000d8f5f7eae21e41978..d3f8876b238a8ab447d3a82ed029b8e923b38872 100644 (file)
@@ -35,7 +35,7 @@ EXTRA_DIST = \
   .x-sc_prohibit_nonreentrant \
   .x-sc_prohibit_sprintf \
   .x-sc_prohibit_strcmp \
-  .x-sc_prohibit_strcmp_and_strncmp \
+  .x-sc_prohibit_strncmp \
   .x-sc_prohibit_strncpy \
   .x-sc_prohibit_test_minus_ao \
   .x-sc_prohibit_VIR_ERR_NO_MEMORY \
diff --git a/cfg.mk b/cfg.mk
index 286b9022c3d1da37e6e9edb74cee73d800138131..0851f44a8ccbd42a9c16f7063a6c49914bebe0ad 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -231,12 +231,14 @@ sc_avoid_write:
        halt='consider using safewrite instead of write'                \
          $(_sc_search_regexp)
 
-# Use STREQ rather than comparing strcmp == 0, or != 0.
-# Similarly, use STREQLEN or STRPREFIX rather than strncmp.
-sc_prohibit_strcmp_and_strncmp:
-       @prohibit='strn?cmp *\('                                        \
-       halt='use STREQ() in place of the above uses of str[n]cmp'      \
-         $(_sc_search_regexp)
+# Similar to the gnulib maint.mk rule for sc_prohibit_strcmp
+# Use STREQLEN or STRPREFIX rather than comparing strncmp == 0, or != 0.
+sc_prohibit_strncmp:
+       @grep -nE '! *str''ncmp *\(|\<str''ncmp *\([^)]+\) *=='         \
+           $$($(VC_LIST_EXCEPT))                                       \
+         | grep -vE ':# *define STREQ\(' &&                            \
+         { echo '$(ME): use STREQLEN or STRPREFIX instead of str''ncmp' \
+               1>&2; exit 1; } || :
 
 # Use virAsprintf rather than as'printf since *strp is undefined on error.
 sc_prohibit_asprintf: