[PATCH 11/38] lib/blkid: suppress -Wstringop-truncation warning in blkid_strndup()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Eric Biggers <ebiggers@xxxxxxxxxx>

Unfortunately, gcc gets confused by blkid_strndup() and incorrectly
thinks the destination string is not being null-terminated.  This is
part of -Wstringop-truncation, enabled automatically by -Wall in gcc 8
and later.  Let's just suppress this warning here.

Signed-off-by: Eric Biggers <ebiggers@xxxxxxxxxx>
---
 lib/blkid/devno.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lib/blkid/devno.c b/lib/blkid/devno.c
index 34ceb3c48..b1cadc9df 100644
--- a/lib/blkid/devno.c
+++ b/lib/blkid/devno.c
@@ -37,6 +37,12 @@
 
 #include "blkidP.h"
 
+#if defined(__GNUC__) && __GNUC__ >= 8
+/* gcc incorrectly thinks the destination string is not being null-terminated */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-truncation"
+#endif
+
 char *blkid_strndup(const char *s, int length)
 {
 	char *ret;
@@ -55,6 +61,10 @@ char *blkid_strndup(const char *s, int length)
 	return ret;
 }
 
+#if defined(__GNUC__) && __GNUC__ >= 8
+#pragma GCC diagnostic pop
+#endif
+
 char *blkid_strdup(const char *s)
 {
 	return blkid_strndup(s, 0);
-- 
2.39.0




[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux