On Thu, 2019-12-12 at 09:10 +0100, Josef Wolf wrote: > Hello, > > I upgraded from gcc-8.2.0 to gcc-9.2.0. > > With gcc-9.2.0, I am getting new warnings for old code, which I have not seen > with gcc-8.2.0 and earlier gcc versions. > > What's more is, that those warnings disappear when OTHER (totally unrelated) > parts of the code is removed. > > > Here is one example (some helper functions for parsing). With the code > attached below, I get this warning: > > $ LANG= PATH=$PATH:/usr/local/crossgcc/bin m68k-unknown-elf-gcc -ansi -pedantic -Wall -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -std=c89 -Wnull-dereference -g -O2 -fno-toplevel-reorder -mcpu32 -c -o t.o t.c > t.c: In function 'get_word': > t.c:53:5: warning: 'strncpy' destination unchanged after copying no bytes > [-Wstringop-truncation] > 53 | strncpy (*r, p, q-p); /* copy */ > | ^~~~~~~~~~~~~~~~~~~~ > > I don't understand this warning at all. The freshly allocated memory is big > enough to hold the copied word including the trailing NUL character. And the > NUL character is appended just behind the copied word. I believe it's telling you that the supplied length is zero and that you haven't changed the destination string. For that to be true, q must have the same value as p. I suspect most of the time a zero length parameter to strncpy is unintentional. > > > When I remove the next_word() function, which is TOTALLY UNRELATED to the code > in question, the warning disappears! That probably affects inlining decisions. jeff >