Whamcloud - gitweb
lib/blkid: suppress -Wstringop-truncation warning in blkid_strndup()
authorEric Biggers <ebiggers@google.com>
Sat, 21 Jan 2023 20:32:03 +0000 (12:32 -0800)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 27 Jan 2023 17:33:59 +0000 (12:33 -0500)
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@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/blkid/devno.c

index 34ceb3c..b1cadc9 100644 (file)
 
 #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);