On Thu, Sep 03, 2020 at 10:47:13AM +0100, Richard W.M. Jones wrote:
A simple reproducer is:
----------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
const char *
copyn (const char *str, size_t n)
{
return strndup (str, n);
}
const char *
copy (const char *str)
{
return copyn (str, SIZE_MAX);
}
----------------------------------------------------------------------
$ gcc -O2 -Wall -c test.c
In function ‘copyn’,
inlined from ‘copy’ at test.c:15:10:
test.c:9:10: warning: ‘strndup’ specified bound 18446744073709551615 exceeds maximum
object size 9223372036854775807 [-Wstringop-overflow=]
9 | return strndup (str, n);
| ^~~~~~~~~~~~~~~~
$ gcc --version
gcc (GCC) 10.2.1 20200826 (Red Hat 10.2.1-3)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I'm still not clear if this is a GCC problem or a code problem,
although Dan pointed out on the list that SIZE_MAX is the largest
size_t, so I guess our code seems OK ...
The error message seems to indicate that the compiler believes a pointer
cannot reference an object larger than SSIZE_MAX and thus doesn't like
the use of SIZE_MAX.
This is quite strange though, given that malloc() and other C functions
pretty much all use size_t for object sizes, not ssize_t.
I think we should try reporting to the GCC maintainers for an opinion
on whether its a compiler bug or not
Regards,
Daniel
--
|:
https://berrange.com -o-
https://www.flickr.com/photos/dberrange :|
|:
https://libvirt.org -o-
https://fstop138.berrange.com :|
|:
https://entangle-photo.org -o-
https://www.instagram.com/dberrange :|