bug-gperf
[Top][All Lists]
Advanced

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

Re: [bug-gperf] avoid compilation warnings


From: Bruno Haible
Subject: Re: [bug-gperf] avoid compilation warnings
Date: Tue, 22 Dec 2009 12:29:29 +0100
User-agent: KMail/1.9.9

Hi Eric,

Eric Blake wrote:
> +       * lib/getopt.c (_getopt_internal): Include ncessary header, and

There is a comment about why <stdlib.h>, <unistd.h> are normally not included.
This applies also to <string.h>. This code predates the gnulib idioms for
overriding system functions and is therefore extremely fragile. Touching this
would require some work with autoconf macros and extensive testing. Which is
just not worth it, for 2 warnings.

> +       avoid warning about ambiguous else.

Thanks, added, with a bit of reindentation.

> +       * tests/smtp.gperf: Avoid undefined behavior.

The patch is fine. But the code did not provoke undefined behaviour,
since it called islower(), toupper() etc. only on characters from the POSIX
basic character set - and on these characters, it is guaranteed that
   (unsigned char) c == (char) c.

> +       * tests/test2.c (O_BINARY): Include necessary header.

Thanks. Added, after verifying that <io.h> indeed exists on all relevant
platforms. (I think it was lacking in very early ports of mingw, or some
such platform.)

Here's what I'm committing in your name:


2009-12-22  Eric Blake  <address@hidden>

        Avoid gcc warnings on Cygwin.
        * lib/getopt.c (_getopt_internal): Add braces. Fix indentation.
        * tests/smtp.gperf: Cast arguments of <ctype.h> functions.
        * tests/test2.c: Include <io.h>.

--- lib/getopt.c.orig   Tue Dec 22 12:18:14 2009
+++ lib/getopt.c        Tue Dec 22 12:04:42 2009
@@ -3,7 +3,7 @@
    "Keep this file name-space clean" means, talk to address@hidden
    before changing it!
 
-   Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98
+   Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 2009
        Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
@@ -686,16 +686,18 @@
              else
                {
                  if (opterr)
-                  if (argv[optind - 1][1] == '-')
-                   /* --option */
-                   fprintf (stderr,
-                    _("%s: option `--%s' doesn't allow an argument\n"),
-                    argv[0], pfound->name);
-                  else
-                   /* +option or -option */
-                   fprintf (stderr,
-                    _("%s: option `%c%s' doesn't allow an argument\n"),
-                    argv[0], argv[optind - 1][0], pfound->name);
+                   {
+                     if (argv[optind - 1][1] == '-')
+                       /* --option */
+                       fprintf (stderr,
+                                _("%s: option `--%s' doesn't allow an 
argument\n"),
+                                argv[0], pfound->name);
+                     else
+                       /* +option or -option */
+                       fprintf (stderr,
+                                _("%s: option `%c%s' doesn't allow an 
argument\n"),
+                                argv[0], argv[optind - 1][0], pfound->name);
+                   }
 
                  nextchar += strlen (nextchar);
 
@@ -711,8 +713,8 @@
                {
                  if (opterr)
                    fprintf (stderr,
-                          _("%s: option `%s' requires an argument\n"),
-                          argv[0], argv[optind - 1]);
+                            _("%s: option `%s' requires an argument\n"),
+                            argv[0], argv[optind - 1]);
                  nextchar += strlen (nextchar);
                  optopt = pfound->val;
                  return optstring[0] == ':' ? ':' : '?';
--- tests/smtp.gperf.orig       Tue Dec 22 12:18:14 2009
+++ tests/smtp.gperf    Tue Dec 22 10:57:26 2009
@@ -183,10 +183,10 @@
           if (len)
             {
               for (k = 0; k < len; k++)
-                if (isupper (s[k]))
-                  s[k] = tolower (s[k]);
-                else if (islower (s[k]))
-                  s[k] = toupper (s[k]);
+                if (isupper ((unsigned char) s[k]))
+                  s[k] = tolower ((unsigned char) s[k]);
+                else if (islower ((unsigned char) s[k]))
+                  s[k] = toupper ((unsigned char) s[k]);
               hs = header_entry (s, len);
               if (!(hs && my_case_strcmp (hs->field_name, s) == 0))
                 {
--- tests/test2.c.orig  Tue Dec 22 12:18:14 2009
+++ tests/test2.c       Tue Dec 22 12:06:57 2009
@@ -15,6 +15,7 @@
 # undef O_BINARY
 #endif
 #if O_BINARY
+# include <io.h>
 # define SET_BINARY(f) setmode (f, O_BINARY)
 #else
 # define SET_BINARY(f) (void)0




reply via email to

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