mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-01-22 13:11:08 +00:00
qemu/compiler: Define QEMU_NONSTRING
GCC 8 introduced the -Wstringop-truncation checker to detect truncation by the strncat and strncpy functions (closely related to -Wstringop-overflow, which detect buffer overflow by string-modifying functions declared in <string.h>). In tandem of -Wstringop-truncation, the "nonstring" attribute was added: The nonstring variable attribute specifies that an object or member declaration with type array of char, signed char, or unsigned char, or pointer to such a type is intended to store character arrays that do not necessarily contain a terminating NUL. This is useful in detecting uses of such arrays or pointers with functions that expect NUL-terminated strings, and to avoid warnings when such an array or pointer is used as an argument to a bounded string manipulation function such as strncpy. From the GCC manual: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-nonstring-variable-attribute Add the QEMU_NONSTRING macro which checks if the compiler supports this attribute. Backports commit 1daff2f8193496b0e5e0ab56dc48c570c81f804e from qemu
This commit is contained in:
parent
b6cc2c4e06
commit
24c56c65a3
|
@ -25,6 +25,21 @@
|
|||
# define QEMU_ERROR(X)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The nonstring variable attribute specifies that an object or member
|
||||
* declaration with type array of char or pointer to char is intended
|
||||
* to store character arrays that do not necessarily contain a terminating
|
||||
* NUL character. This is useful in detecting uses of such arrays or pointers
|
||||
* with functions that expect NUL-terminated strings, and to avoid warnings
|
||||
* when such an array or pointer is used as an argument to a bounded string
|
||||
* manipulation function such as strncpy.
|
||||
*/
|
||||
#if __has_attribute(nonstring)
|
||||
# define QEMU_NONSTRING __attribute__((nonstring))
|
||||
#else
|
||||
# define QEMU_NONSTRING
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// MSVC support
|
||||
|
||||
|
|
Loading…
Reference in a new issue