Le 30/04/2019 à 23:01, Alistair Francis a écrit : > On Tue, Apr 30, 2019 at 1:36 PM Laurent Vivier <laur...@vivier.eu> wrote: >> >> Le 30/04/2019 à 22:09, Alistair Francis a écrit : >>> Fix this warning when building with GCC9 on Fedora 30: >>> In function ‘strncpy’, >>> inlined from ‘fill_psinfo’ at >>> /home/alistair/qemu/linux-user/elfload.c:3208:12, >>> inlined from ‘fill_note_info’ at >>> /home/alistair/qemu/linux-user/elfload.c:3390:5, >>> inlined from ‘elf_core_dump’ at >>> /home/alistair/qemu/linux-user/elfload.c:3539:9: >>> /usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ >>> specified bound 16 equals destination size [-Werror=stringop-truncation] >>> 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos >>> (__dest)); >>> | >>> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>> >>> Signed-off-by: Alistair Francis <alistair.fran...@wdc.com> >>> --- >>> linux-user/elfload.c | 4 ++-- >>> 1 file changed, 2 insertions(+), 2 deletions(-) >>> >>> diff --git a/linux-user/elfload.c b/linux-user/elfload.c >>> index c1a26021f8..cbb7fc10fa 100644 >>> --- a/linux-user/elfload.c >>> +++ b/linux-user/elfload.c >>> @@ -3206,7 +3206,7 @@ static int fill_psinfo(struct target_elf_prpsinfo >>> *psinfo, const TaskState *ts) >> >> /* >> * Using strncpy here is fine: at max-length, >>> * this field is not NUL-terminated. >>> */> (void) strncpy(psinfo->pr_fname, base_filename, >>> - sizeof(psinfo->pr_fname)); >>> + sizeof(psinfo->pr_fname) - 1); >> >> Read the comment above :) > > GCC can't read the comment though. The only other option I can think > of is using a pragma, which I avoided using unless I had to. Would you > prefer a pragma here? Or do you have a better solution? >
perhaps: memcpy(psinfo->pr_fname, base_filename, MIN(strlen(base_filename) + 1, sizeof(psinfo->pr_fname)); ? Thanks, Laurent