From ecd910ae3a2c0b29d49602aa71f400be3794184f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 14 Aug 2024 08:43:08 +0300 Subject: [PATCH] MDEV-34755 g++- -Wstringop-truncation due to safe_strcpy() The #pragma that was removed in commit e255837eaf90e72eaf122d88b30011db17f7ecf2 (MDEV-34266) turns out to be necessary for silencing all cases of -Wstringop-truncation. --- include/m_string.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/m_string.h b/include/m_string.h index 3da252b0912..ddfaf84b2d0 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -255,9 +255,20 @@ static inline void safe_strcpy(char *dst, size_t dst_size, const char *src) * * 2) IF there is no 0 byte in the first dst_size bytes of src, strncpy will * copy dst_size bytes, and the final byte won't be 0. + * + * In GCC 8+, the `-Wstringop-truncation` warning may object to strncpy() + * being used in this way, so we need to disable this warning for this + * single statement. */ +#if defined __GNUC__ && __GNUC__ >= 8 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-truncation" +#endif strncpy(dst, src, dst_size); +#if defined __GNUC__ && __GNUC__ >= 8 +#pragma GCC diagnostic pop +#endif dst[dst_size - 1]= 0; }