gcc-4.6.0-0.12.fc15.x86_64 breaks strcmp?

Jim Meyering jim at meyering.net
Mon Mar 7 16:15:18 UTC 2011


Adam Jackson wrote:

> On 3/7/11 10:35 AM, Richard W.M. Jones wrote:
>
>> Below is how the failure line expands(!)
>
> Thanks, I needed a laugh this morning.
>
> If I do this as a minimal testcase:
>
> ---
>
> #include <string.h>
> #include <stdio.h>
>
> int
> do_rm_rf (const char *path)
> {
>    int r;
>    char *buf, *err;
>
>    if (!strcmp(path, "/")) {
>      printf ("cannot remove root directory");
>      return -1;
>    }
>
>    return 0;
> }

Shame on me.
I forgot string.h and -Wall ;-)

With the former and -O3, I do see your warning.
Here's a pared-down test case:

    $ cat k.c
    #include <string.h>
    void do_rm_rf (const char *p) { if (strcmp (p, "/") == 0) return; }
    $ gcc -Wall -O3 -c k.c -Werror=strict-overflow
    k.c: In function ‘do_rm_rf’:
    k.c:2:1678: error: assuming signed overflow does not occur when changing X +- C1 cmp C2 to X cmp C1 +- C2 [-Werror=strict-overflow]
    cc1: some warnings being treated as errors

    [Exit 1]


More information about the devel mailing list