bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: manywarnings: -Walloc-size-larger-than & 32bit architectures


From: Richard W.M. Jones
Subject: Re: manywarnings: -Walloc-size-larger-than & 32bit architectures
Date: Mon, 31 Jul 2017 14:12:49 +0100
User-agent: Mutt/1.5.20 (2009-12-10)

On Mon, Jul 31, 2017 at 02:15:16PM +0200, Pino Toscano wrote:
> Hi,
> 
> when using the warnings module, after commit
> 5e22aee79f9d02ac37f40f1d18f5696114c3c3c9 also
> -Walloc-size-larger-than=9223372036854775807 is added to the CFLAGS,
> if supported (which seems the case with newer GCC versions).  However,
> the value is too big for 32bit architectures, so this will "break" the
> GCC checks.  Let's see the following example on a i686 version of
> Fedora 26:
> 
> $ cat test.c 
> #include <stdlib.h>
> int main(void)
> {
>   char *foo = malloc(5);
>   free(foo);
>   return 0;
> }
> $ gcc -Walloc-size-larger-than=9223372036854775807 -o test test.c 
> test.c: In function ‘main’:
> test.c:4:9: warning: argument 1 value ‘5’ exceeds maximum object size -1 
> [-Walloc-size-larger-than=]

Could this be a bug in GCC?  It's turning 2^63-1 into -1 without even
issuing a warning ...

Rich.

>    char *foo = malloc(5);
>          ^~~
> In file included from test.c:1:0:
> /usr/include/stdlib.h:443:14: note: in a call to allocation function ‘malloc’ 
> declared here
>  extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
>               ^~~~~~
> $ gcc --version
> gcc (GCC) 7.1.1 20170622 (Red Hat 7.1.1-3)
> $ uname -a
> Linux fedora 4.11.11-300.fc26.i686+PAE #1 SMP Mon Jul 17 16:53:51 UTC 2017 
> i686 i686 i386 GNU/Linux
> 
> Using the PTRDIFF_MAX value on such architecture, i.e. 2147483647,
> indeed makes the issue go away, and the GCC checks work again (that is,
> not showing all the allocations as false positives).
> 
> Does anyone have an idea (or even a patch) to make gnulib pass the
> right value to GCC?
> 
> Thanks,
> -- 
> Pino Toscano



-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top



reply via email to

[Prev in Thread] Current Thread [Next in Thread]