[PATCH] BZ #14083 Fix strspn warning with -Wconversion

Carlos O'Donell carlos@systemhalted.org
Wed May 9 13:25:00 GMT 2012


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.



More information about the Libc-alpha mailing list