New -Wrestrict warning with GCC9
Brought to you by:
bkorb
Using latest GCC, one can see:
$ /bin/sh ../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I.. -I.. -I../autoopts -DPKGDATADIR='"/usr/local/share/autogen"' -g -O2 -Wno-format-contains-nul -fno-strict-aliasing -Wall -Werror -Wcast-align -Wmissing-prototypes -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings -Wstrict-aliasing=3 -Wextra -Wno-cast-qual -g -O2 -Wno-format-contains-nul -fno-strict-aliasing -c -o libopts_la-libopts.lo `test -f 'libopts.c' || echo './'`libopts.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I.. -I.. -I../autoopts -DPKGDATADIR=\"/usr/local/share/autogen\" -g -O2 -Wno-format-contains-nul -fno-strict-aliasing -Wall -Werror -Wcast-align -Wmissing-prototypes -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings -Wstrict-aliasing=3 -Wextra -Wno-cast-qual -g -O2 -Wno-format-contains-nul -fno-strict-aliasing -c libopts.c -fPIC -DPIC -o .libs/libopts_la-libopts.o
In file included from autoopts.c:42,
from libopts.c:22:
In function ‘canonicalize_pathname’,
inlined from ‘option_pathfind.constprop’ at ../compat/pathfind.c:88:32:
../compat/pathfind.c:214:17: error: ‘strcpy’ accessing 1 byte at offsets [0, 9223372036854775807] and [0, 9223372036854775807] may overlap 1 byte at offset 0 [-Werror=restrict]
214 | strcpy( result + start + 1, result + i + 2 );
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It's explained and analyzed here:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88973
I didn't write this code. The person who did is no longer able to help (employer restriction). I haven't been writing code for 5 years, so a patch would be welcome. :)
Otherwise, I'll take a gander when I get back from an out-of-country wedding this April.
I can come up with a patch candidate.
Patch candiate:
Any opinion about the patch? Thanks.
Looks good to me, but strcpy should have been a void procedure from the get-go.
Since we're fixing a warning triggered by a "we must warn about every
conceivable
issue", the return value from strcpy/strcpy_overlapping is ignored. May as well
make this warning-go-away fix be scrupulous, too:
static void
strcpy_overlapping(char d, const char s)
{
memmove(d, s, strlen(s) + 1);
}
I'll be back from a wedding the end of March.
On Tue, Feb 26, 2019 at 2:19 AM "Martin Liška"
marxin@users.sourceforge.net wrote:
Related
Bugs:
#193strcpy-s were replaced with memmove directly.
fixed.