This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] BZ #14083 Fix strspn warning with -Wconversion
- From: Andreas Jaeger <aj at suse dot de>
- To: libc-alpha at sourceware dot org
- Date: Wed, 09 May 2012 15:18:52 +0200
- Subject: [PATCH] BZ #14083 Fix strspn warning with -Wconversion
This simple program:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
size_t x;
x = strspn("hello","h");
printf("%zd\n", x);
return 0;
}
gives a warning with -Wconversion:
$ gcc -Wconversion -O t.c
t.c: In function âmainâ:
t.c:8:7: warning: conversion to âlong unsigned intâ from âintâ may change the sign of the result [-Wsign-conversion]
Fixed with the appended patch, tested on Linux/x86-64. Ok to commit?
For details see also
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53277
Andreas
2012-05-09 Andreas Jaeger <aj@suse.de>
[BZ #14083]
* string/bits/string2.h (strspn) [__GNUC_PREREQ(3, 2) &&
!_HAVE_STRING_ARCH_strspn]: Cast zero to size_t to avoid
-Wconversion warning.
(strspn) [!__GNUC_PREREQ(3, 2) && !_HAVE_STRING_ARCH_strspn]:
Likewise.
diff --git a/string/bits/string2.h b/string/bits/string2.h
index af5c88c..bbf05a3 100644
--- a/string/bits/string2.h
+++ b/string/bits/string2.h
@@ -1014,7 +1014,7 @@ __strcspn_c3 (const char *__s, int __reject1, int __reject2,
? ((__builtin_constant_p (s) && __string2_1bptr_p (s)) \
? __builtin_strspn (s, accept) \
: ((__a0 = ((const char *) (accept))[0], __a0 == '\0') \
- ? ((void) (s), 0) \
+ ? ((void) (s), (size_t) 0) \
: ((__a1 = ((const char *) (accept))[1], __a1 == '\0') \
? __strspn_c1 (s, __a0) \
: ((__a2 = ((const char *) (accept))[2], __a2 == '\0') \
@@ -1029,7 +1029,7 @@ __strcspn_c3 (const char *__s, int __reject1, int __reject2,
({ char __a0, __a1, __a2; \
(__builtin_constant_p (accept) && __string2_1bptr_p (accept) \
? ((__a0 = ((const char *) (accept))[0], __a0 == '\0') \
- ? ((void) (s), 0) \
+ ? ((void) (s), (size_t) 0) \
: ((__a1 = ((const char *) (accept))[1], __a1 == '\0') \
? __strspn_c1 (s, __a0) \
: ((__a2 = ((const char *) (accept))[2], __a2 == '\0') \
--
Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 NÃrnberg, Germany
GF: Jeff Hawn,Jennifer Guild,Felix ImendÃrffer,HRB16746 (AG NÃrnberg)
GPG fingerprint = 93A3 365E CE47 B889 DF7F FED1 389A 563C C272 A126