Suppress warning for snprintf truncation test.

This commit is contained in:
Darren Tucker 2023-05-09 17:13:33 +10:00
parent 47742c513e
commit 5fbb7a1349
No known key found for this signature in database
1 changed files with 7 additions and 2 deletions

View 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 */