On Fri, Jan 24, 2020 at 10:31:14AM +0100, Willy Tarreau wrote:
> This is really annoying, so much time spent dealing with bogus warnings
> is really irritating. I'm going to work around it with a cast to unsigned
> short.
> 
> The worst part of it is that if it emits such a warning, who knows how valid
> is the code that it will produce given that it doesn't even seem to figure
> the code path :-(

So I could isolate the minimum code to reproduce the bug:

    #include <stdlib.h>
    
    int nbt = 64;
    
    struct srv {
            void *a[5];
            int **b;
    };
    
    void check_config_validity4(struct srv *srv, unsigned int *v)
    {
            int i;
    
            for (i = 0; i < nbt; i++)
                    (*v)++;
     
            srv->b = calloc(/*(unsigned int)*/nbt, sizeof(*srv->b));
            for (i = 0; i < nbt; i++)
                    srv->b[i] = 0;
    }

Just change the fields ordering in "struct srv" or the size of field "a"
and the bug disappears. Remove any of the loops or make it not depend on
nbt and the bug disappears. Casting nbt to unsigned has no effect. It
always emits the same warning as seen, and only on 32-bits.

When I have a bit of spare time I may file a bug to gcc with this excerpt,
unless someone wants to handle it, of course. Even once fixed it will
probably not flow down to distros given that it's not critical, so we'll
have to work around it as we can.

Willy

Reply via email to