]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
Suppress warning for snprintf truncation test.
authorDarren Tucker <dtucker@dtucker.net>
Tue, 9 May 2023 07:13:33 +0000 (17:13 +1000)
committerDarren Tucker <dtucker@dtucker.net>
Tue, 9 May 2023 07:13:33 +0000 (17:13 +1000)
openbsd-compat/regress/snprintftest.c

index a3134db1ca947423d77d168e62a5858f64f35f14..87b72ca38e378587125839a0228c5d67a481d315 100644 (file)
@@ -25,6 +25,9 @@
 #include <stdarg.h>
 #include <string.h>
 
+/* Suppress format truncation warning since we're explicitly testing that. */
+#pragma GCC diagnostic ignored "-Wformat-truncation"
+
 static int failed = 0;
 
 static void
@@ -50,9 +53,11 @@ main(void)
 {
        char b[5];
        char *src = NULL;
+       int ret;
 
-       snprintf(b,5,"123456789");
-       if (b[4] != '\0')
+       memset(b, 'X', sizeof(b));
+       ret = snprintf(b, 5, "123456789");
+       if (ret != 9 || b[4] != '\0')
                fail("snprintf does not correctly terminate long strings");
 
        /* check for read overrun on unterminated string */