[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v1 5/5] linux-user/elfload: Fix GCC 9 build warn
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH v1 5/5] linux-user/elfload: Fix GCC 9 build warnings |
Date: |
Tue, 30 Apr 2019 16:10:07 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 |
On 4/30/19 4:01 PM, Alistair Francis wrote:
> On Tue, Apr 30, 2019 at 1:36 PM Laurent Vivier <address@hidden> 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));
>>> |
>>> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>
>> /*
>> * 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?
psinfo is struct target_elf_prpsinfo, which we declare. Why not just
use the QEMU_NONSTRING attribute in the declaration, to tell the
compiler our exact intents (untested, but something like this):
diff --git i/linux-user/elfload.c w/linux-user/elfload.c
index c1a26021f8d..6ebb2eeb957 100644
--- i/linux-user/elfload.c
+++ w/linux-user/elfload.c
@@ -2872,7 +2872,7 @@ struct target_elf_prpsinfo {
target_gid_t pr_gid;
target_pid_t pr_pid, pr_ppid, pr_pgrp, pr_sid;
/* Lots missing */
- char pr_fname[16]; /* filename of executable */
+ char pr_fname[16] QEMU_NONSTRING; /* filename of
executable */
char pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */
};
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature
- [Qemu-devel] [PATCH v1 4/5] linux-user/uname: Fix GCC 9 build warnings, (continued)