GCC 11 warns about string and memory operations on fixed address: In function 'memcpy', inlined from 'obd_uuid2str' at lustre/include/uapi/linux/lustre/lustre_user.h:1222:3, include/linux/fortify-string.h:20:33: error: '__builtin_memcpy' reading 39 bytes from a region of size 0 [-Werror=stringop-overread] 20 | #define __underlying_memcpy __builtin_memcpy | ^ include/linux/fortify-string.h:191:16: note: in expansion of macro '__underlying_memcpy' 191 | return __underlying_memcpy(p, q, size); | ^~~~~~~~~~~~~~~~~~~ The patch avoids the above warning by not using a fixed address. WC-bug-id: https://jira.whamcloud.com/browse/LU-15220 Lustre-commit: c5fb44f5ecf8494cd ("LU-15220 tests: avoid gcc-11 -Werror=stringop-overread warning") Signed-off-by: Jian Yu <yujian@xxxxxxxxxxxxx> Reviewed-on: https://review.whamcloud.com/45777 WC-bug-id: https://jira.whamcloud.com/browse/LU-15420 Lustre-commit: 6331eadbd60a8c58c ("LU-15420 uapi: avoid gcc-11 -Werror=stringop-overread") Signed-off-by: James Simmons <jsimmons@xxxxxxxxxxxxx> Reviewed-on: https://review.whamcloud.com/46319 Reviewed-by: Alexey Lyashkov <alexey.lyashkov@xxxxxxx> Reviewed-by: Arshad Hussain <arshad.hussain@xxxxxxxxxxxxxxxxx> Reviewed-by: Patrick Farrell <pfarrell@xxxxxxxxxxxxx> Reviewed-by: James Simmons <jsimmons@xxxxxxxxxxxxx> Reviewed-by: Oleg Drokin <green@xxxxxxxxxxxxx> --- include/uapi/linux/lustre/lustre_user.h | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/include/uapi/linux/lustre/lustre_user.h b/include/uapi/linux/lustre/lustre_user.h index ee789f2..c57929b 100644 --- a/include/uapi/linux/lustre/lustre_user.h +++ b/include/uapi/linux/lustre/lustre_user.h @@ -40,26 +40,27 @@ * * @{ */ +#include <linux/string.h> +#ifndef __KERNEL__ +# define __USE_ISOC99 1 +# include <stdbool.h> +# include <stdio.h> /* snprintf() */ +# include <sys/stat.h> + +# define __USE_GNU 1 +# define FILEID_LUSTRE 0x97 /* for name_to_handle_at() (and llapi_fd2fid()) */ +#endif /* !__KERNEL__ */ #include <linux/fs.h> #include <linux/limits.h> #include <linux/kernel.h> #include <linux/stat.h> -#include <linux/string.h> #include <linux/quota.h> #include <linux/types.h> #include <linux/unistd.h> #include <linux/lustre/lustre_fiemap.h> #include <linux/lustre/lustre_ver.h> -#ifndef __KERNEL__ -# define __USE_ISOC99 1 -# include <stdbool.h> -# include <stdio.h> /* snprintf() */ -# include <sys/stat.h> -# define FILEID_LUSTRE 0x97 /* for name_to_handle_at() (and llapi_fd2fid()) */ -#endif /* __KERNEL__ */ - #if defined(__cplusplus) extern "C" { #endif @@ -937,10 +938,11 @@ static inline char *obd_uuid2str(const struct obd_uuid *uuid) /* Obviously not safe, but for printfs, no real harm done... * we're always null-terminated, even in a race. */ - static char temp[sizeof(*uuid)]; + static char temp[sizeof(*uuid->uuid)]; + + memcpy(temp, uuid->uuid, sizeof(*uuid->uuid) - 1); + temp[sizeof(*uuid->uuid) - 1] = '\0'; - memcpy(temp, uuid->uuid, sizeof(*uuid) - 1); - temp[sizeof(*uuid) - 1] = '\0'; return temp; } return (char *)(uuid->uuid); -- 1.8.3.1