This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] BZ #14083 Fix strspn warning with -Wconversion
- From: "Carlos O'Donell" <carlos at systemhalted dot org>
- To: Andreas Jaeger <aj at suse dot de>
- Cc: libc-alpha at sourceware dot org
- Date: Wed, 9 May 2012 09:25:34 -0400
- Subject: Re: [PATCH] BZ #14083 Fix strspn warning with -Wconversion
- References: <hoaa1hcx1f.fsf@byrd.suse.de>
On Wed, May 9, 2012 at 9:18 AM, Andreas Jaeger <aj@suse.de> wrote:
>
> 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.
This looks good to me.
Cheers,
Carlos.