]> xenbits.xensource.com Git - libvirt.git/commitdiff
maint: avoid locale-sensitivity in string case comparisons
authorEric Blake <eblake@redhat.com>
Thu, 31 Mar 2011 02:26:27 +0000 (20:26 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 31 Mar 2011 02:26:27 +0000 (20:26 -0600)
strcase{cmp/str} have the drawback of being sensitive to the global
locale; this is unacceptable in a library setting.  Prefer a
hard-coded C locale alternative for all but virsh, which is user
facing and where the global locale isn't changing externally.

* .gnulib: Update to latest, for c-strcasestr change.
* bootstrap.conf (gnulib_modules): Drop strcasestr, add c-strcase
and c-strcasestr.
* cfg.mk (sc_avoid_strcase): New rule.
(exclude_file_name_regexp--sc_avoid_strcase): New exception.
* src/internal.h (STRCASEEQ, STRCASENEQ, STRCASEEQLEN)
(STRCASENEQLEN): Adjust offenders.
* src/qemu/qemu_monitor_text.c (qemuMonitorTextEjectMedia):
Likewise.
* tools/virsh.c (namesorter): Document exception.

.gnulib
bootstrap.conf
cfg.mk
src/internal.h
src/qemu/qemu_monitor_text.c
tools/virsh.c

diff --git a/.gnulib b/.gnulib
index 422ab2e0d70ed348e2fd0a82558be38e5859011a..790645d837f8084991421107fba639b110d58335 160000 (submodule)
--- a/.gnulib
+++ b/.gnulib
@@ -1 +1 @@
-Subproject commit 422ab2e0d70ed348e2fd0a82558be38e5859011a
+Subproject commit 790645d837f8084991421107fba639b110d58335
index 6e10828814b3df6ceaa327e438353526d1b3ee6d..733c3541c769598b25053294ccd51470e908b0d2 100644 (file)
@@ -22,6 +22,8 @@ gnulib_modules='
 areadlink
 base64
 c-ctype
+c-strcase
+c-strcasestr
 canonicalize-lgpl
 chown
 close
@@ -63,7 +65,6 @@ sigpipe
 snprintf
 socket
 stpcpy
-strcasestr
 strchrnul
 strndup
 strerror
diff --git a/cfg.mk b/cfg.mk
index ac419f74a8c3dbaf6789c5678b18b5376b2c3243..f802cee494a231b883266a0d975b0d1580f929a0 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -349,6 +349,11 @@ sc_avoid_ctype_macros:
        halt="don't use ctype macros (use c-ctype.h)"                   \
          $(_sc_search_regexp)
 
+sc_avoid_strcase:
+       @prohibit='\bstrn?case(cmp|str) *\('                            \
+       halt="don't use raw strcase functions (use c-strcase instead)"  \
+         $(_sc_search_regexp)
+
 sc_prohibit_virBufferAdd_with_string_literal:
        @prohibit='\<virBufferAdd *\([^,]+, *"[^"]'                     \
        halt='use virBufferAddLit, not virBufferAdd, with a string literal' \
@@ -547,6 +552,8 @@ _makefile_at_at_check_exceptions = ' && !/(SCHEMA|SYSCONF)DIR/'
 syntax-check: $(top_srcdir)/HACKING
 
 # List all syntax-check exemptions:
+exclude_file_name_regexp--sc_avoid_strcase = ^tools/virsh\.c$$
+
 _src1=libvirt|fdstream|qemu/qemu_monitor|util/(command|util)|xen/xend_internal
 exclude_file_name_regexp--sc_avoid_write = \
   ^(src/($(_src1))|daemon/libvirtd|tools/console)\.c$$
index be9780171b476c3a74cfc7e22acaba2d06d9c4bc..2afbd8db427b6aa91abf3d5b63ffe616e6ad9521 100644 (file)
@@ -44,6 +44,8 @@
 
 # include "libvirt_internal.h"
 
+# include "c-strcase.h"
+
 /* On architectures which lack these limits, define them (ie. Cygwin).
  * Note that the libvirt code should be robust enough to handle the
  * case where actual value is longer than these limits (eg. by setting
 
 /* String equality tests, suggested by Jim Meyering. */
 # define STREQ(a,b) (strcmp(a,b) == 0)
-# define STRCASEEQ(a,b) (strcasecmp(a,b) == 0)
+# define STRCASEEQ(a,b) (c_strcasecmp(a,b) == 0)
 # define STRNEQ(a,b) (strcmp(a,b) != 0)
-# define STRCASENEQ(a,b) (strcasecmp(a,b) != 0)
+# define STRCASENEQ(a,b) (c_strcasecmp(a,b) != 0)
 # define STREQLEN(a,b,n) (strncmp(a,b,n) == 0)
-# define STRCASEEQLEN(a,b,n) (strncasecmp(a,b,n) == 0)
+# define STRCASEEQLEN(a,b,n) (c_strncasecmp(a,b,n) == 0)
 # define STRNEQLEN(a,b,n) (strncmp(a,b,n) != 0)
-# define STRCASENEQLEN(a,b,n) (strncasecmp(a,b,n) != 0)
+# define STRCASENEQLEN(a,b,n) (c_strncasecmp(a,b,n) != 0)
 # define STRPREFIX(a,b) (strncmp(a,b,strlen(b)) == 0)
 # define STRSKIP(a,b) (STRPREFIX(a,b) ? (a) + strlen(b) : NULL)
 
index e0e32929db95e1b3469aba9847d4f692e8877ffe..168c60fdaa715d109df196db15e685556bff2b11 100644 (file)
@@ -33,6 +33,7 @@
 #include "qemu_monitor_text.h"
 #include "qemu_command.h"
 #include "c-ctype.h"
+#include "c-strcasestr.h"
 #include "memory.h"
 #include "logging.h"
 #include "driver.h"
@@ -934,7 +935,7 @@ int qemuMonitorTextEjectMedia(qemuMonitorPtr mon,
     /* If the command failed qemu prints:
      * device not found, device is locked ...
      * No message is printed on success it seems */
-    if (strcasestr(reply, "device ")) {
+    if (c_strcasestr(reply, "device ")) {
         qemuReportError(VIR_ERR_OPERATION_FAILED,
                         _("could not eject media on %s: %s"), devname, reply);
         goto cleanup;
index faeaf472f7298824168a455a5d41fc74ef2cbd59..3c759b948d267a02715e00099b695312ae23f238 100644 (file)
@@ -432,6 +432,7 @@ static int namesorter(const void *a, const void *b) {
   const char **sa = (const char**)a;
   const char **sb = (const char**)b;
 
+  /* User visible sort, so we want locale-specific case comparison.  */
   return strcasecmp(*sa, *sb);
 }