bug-gnulib
[Top][All Lists]
Advanced

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

argp: listen to gcc warnings


From: Bruno Haible
Subject: argp: listen to gcc warnings
Date: Sat, 24 Mar 2007 12:22:09 +0100
User-agent: KMail/1.5.4

Hi,

Compiling the 'argp' module on NetBSD with "-Wall" yields these warnings:

argp-help.c:172: warning: subscript has type `char'
argp-help.c:174: warning: subscript has type `char'
argp-help.c:181: warning: subscript has type `char'
argp-help.c:185: warning: subscript has type `char'
argp-help.c:192: warning: subscript has type `char'
argp-help.c:206: warning: subscript has type `char'
argp-help.c:209: warning: subscript has type `char'
argp-help.c:211: warning: subscript has type `char'
argp-help.c:723: warning: subscript has type `char'
argp-help.c:728: warning: subscript has type `char'

When you look at the code, you see that the user only has to set the variable
ARGP_HELP_FMT to a value containing non-ASCII characters, to make the program
crash. Note that the code in glibc does not have this problem, since in glibc
(and only in glibc!) the <ctype.h> functions may also be called with values
in the range -128..-1.

I'm applying this. Sergey, I guess you don't have a better fix for it?

2007-03-24  Bruno Haible  <address@hidden>

        * lib/argp-help.c (fill_in_uparams, canon_doc_option): Cast the
        arguments of isspace, isalpha, isalnum, isdigit to 'unsigned char'.

--- lib/argp-help.c     12 Sep 2006 09:06:40 -0000      1.25
+++ lib/argp-help.c     24 Mar 2007 11:10:27 -0000
@@ -1,5 +1,5 @@
 /* Hierarchial argument parsing help output
-   Copyright (C) 1995-2003, 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 1995-2005, 2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Miles Bader <address@hidden>.
 
@@ -162,7 +162,7 @@
   const char *var = getenv ("ARGP_HELP_FMT");
   struct uparams new_params = uparams;
   
-#define SKIPWS(p) do { while (isspace (*p)) p++; } while (0);
+#define SKIPWS(p) do { while (isspace ((unsigned char) *p)) p++; } while (0);
 
   if (var)
     {
@@ -171,14 +171,14 @@
        {
          SKIPWS (var);
          
-         if (isalpha (*var))
+         if (isalpha ((unsigned char) *var))
            {
              size_t var_len;
              const struct uparam_name *un;
              int unspec = 0, val = 0;
              const char *arg = var;
 
-             while (isalnum (*arg) || *arg == '-' || *arg == '_')
+             while (isalnum ((unsigned char) *arg) || *arg == '-' || *arg == 
'_')
                arg++;
              var_len = arg - var;
              
@@ -203,10 +203,10 @@
                  else
                    val = 1;
                }
-             else if (isdigit (*arg))
+             else if (isdigit ((unsigned char) *arg))
                {
                  val = atoi (arg);
-                 while (isdigit (*arg))
+                 while (isdigit ((unsigned char) *arg))
                    arg++;
                  SKIPWS (arg);
                }
@@ -720,12 +720,12 @@
   else
     {
       /* Skip initial whitespace.  */
-      while (isspace (**name))
+      while (isspace ((unsigned char) **name))
        (*name)++;
       /* Decide whether this looks like an option (leading `-') or not.  */
       non_opt = (**name != '-');
       /* Skip until part of name used for sorting.  */
-      while (**name && !isalnum (**name))
+      while (**name && !isalnum ((unsigned char) **name))
        (*name)++;
     }
   return non_opt;





reply via email to

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