[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] fix build warning in fnmatch_loop.c
From: |
Eric Blake |
Subject: |
Re: [PATCH] fix build warning in fnmatch_loop.c |
Date: |
Sat, 14 Nov 2009 15:41:59 -0700 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Robert Millan on 11/14/2009 8:30 AM:
>>>> : p - startp + 1U;
>>>>
>>>> to still show that we intend for unsigned math, but without a cast?
>>> The warning persists.
>> Can you show the exact gcc version, command line options, and warning
>> output that you are seeing with this construct?
>
> gcc-4.4 -Ignulib -I./gnulib -I. -I./include -I./include -Wall -W
> -DGRUB_LIBDIR=\"/usr/local/lib/`echo grub/i386-pc | sed 's,x,x,'`\" -g -O2
> -DGRUB_UTIL=1 -D_FILE_OFFSET_BITS=64 -I./util/mkisofs/include -I./gnulib
> -Wno-all -Werror -MD -c -o grub_mkisofs-gnulib_fnmatch.o gnulib/fnmatch.c
> cc1: warnings being treated as errors
> In file included from gnulib/fnmatch.c:173:
> gnulib/fnmatch_loop.c: In function ‘ext_match’:
> gnulib/fnmatch_loop.c:1087: error: signed and unsigned type in conditional
> expression
> gnulib/fnmatch_loop.c:1095: error: signed and unsigned type in conditional
> expression
>
> This is GCC 4.4.2. With 4.3.2 I get the same result.
With 1U, I can't reproduce your warning with gcc 4.3.4 on a 32-bit machine:
$ cat foo.c
#include <sys/types.h>
#ifndef bar
# define bar 1
#endif
int
main (int argc, char **argv)
{
size_t plen;
size_t patt = 1;
char *p = "abc", *startp = p + 1;
plen = argc > 1 ? patt : p - startp + bar;
return !!argv[0];
}
$ gcc -Wall -W foo.c -o foo
foo.c: In function `main':
foo.c:11: warning: signed and unsigned type in conditional expression
$ gcc -Wall -W foo.c -o foo -Dbar=1U
$
Oh, I see. I repeated the experiment on a 64-bit machine, and got the
same error even with -Dbar=1U. It comes because (p - startp) is a 64-bit
ptrdiff_t, but 1U is only 32-bit, so it promotes to long rather than
unsigned long, leaving us in the same boat. But using -Dbar=1LU made the
warning go away. So I'm committing this:
- --
Don't work too hard, make some time for fun as well!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkr/MjYACgkQ84KuGfSFAYCCVwCeKmRVO7UMNZizfmA+pzam9HRH
xDIAnA2x2uXQabcJSeKnuAnCAdwdI7h/
=hVRL
-----END PGP SIGNATURE-----
From a86ea846c82189cec7b2fad8679377d5475211c1 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Sat, 14 Nov 2009 15:25:49 -0700
Subject: [PATCH] fnmatch: avoid compiler warning
cond ? (size_t) : (char* - char* + 1) varies in signedness, but
using 1LU coerces the latter half to unsigned math.
* lib/fnmatch_loop.c (NEW_PATTERN): Coerce addition to unsigned,
to silence compiler warning about mismatch signedness in ?:.
Reported by Robert Millan.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 5 +++++
lib/fnmatch_loop.c | 4 ++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4ff76e7..a241c5b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2009-11-14 Eric Blake <address@hidden>
+ fnmatch: avoid compiler warning
+ * lib/fnmatch_loop.c (NEW_PATTERN): Coerce addition to unsigned,
+ to silence compiler warning about mismatch signedness in ?:.
+ Reported by Robert Millan.
+
intprops: add double-inclusion guard
* lib/intprops.h: Allow idempotent includes.
Suggested by Bruce Korb.
diff --git a/lib/fnmatch_loop.c b/lib/fnmatch_loop.c
index d1008c2..ad58bb2 100644
--- a/lib/fnmatch_loop.c
+++ b/lib/fnmatch_loop.c
@@ -1,4 +1,4 @@
-/* Copyright (C)
1991,1992,1993,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006
+/* Copyright (C)
1991,1992,1993,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2009
Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -1071,7 +1071,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string,
const CHAR *string_end,
\
plen = (opt == L_('?') || opt == L_('@') \
? pattern_len \
- : p - startp + 1); \
+ : p - startp + 1UL); \
plensize = plen * sizeof (CHAR); \
newpsize = offsetof (struct patternlist, str) + plensize; \
if ((size_t) -1 / sizeof (CHAR) < plen \
--
1.6.5.rc1
Re: [PATCH] fix build warning in fnmatch_loop.c, Robert Millan, 2009/11/09