From: Gary Lockyer Date: Mon, 19 May 2025 22:00:26 +0000 (+1200) Subject: Fix clang 20 format-truncation warnings X-Git-Tag: tevent-0.17.0~81 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b6fede171ebd228539a3d879ec9d55d9b8901d89;p=thirdparty%2Fsamba.git Fix clang 20 format-truncation warnings Fix: lib/replace/tests/testsuite.c:387:6: error: 'snprintf' will always be truncated; specified size is 3, but format string expands to at least 5 [-Werror,-Wformat-truncation] 387 | if (snprintf(tmp, 3, "foo%d", 9) != 4) { | ^ As this is an explicit test of snprintf's truncation behaviour the warning can be safely suppressed. Signed-off-by: Gary Lockyer Reviewed-by: Douglas Bagnall Reviewed-by: Anoop C S --- diff --git a/buildtools/wafsamba/samba_autoconf.py b/buildtools/wafsamba/samba_autoconf.py index 255e63b7ff8..31a20c812c5 100644 --- a/buildtools/wafsamba/samba_autoconf.py +++ b/buildtools/wafsamba/samba_autoconf.py @@ -843,7 +843,6 @@ int main(void) { conf.ADD_NAMED_CFLAGS('PICKY_CFLAGS', '-Werror -Wno-error=deprecated-declarations', testflags=True) conf.ADD_NAMED_CFLAGS('PICKY_CFLAGS', '-Wno-error=tautological-compare', testflags=True) conf.ADD_NAMED_CFLAGS('PICKY_CFLAGS', '-Wno-error=cast-align', testflags=True) - conf.ADD_NAMED_CFLAGS('PICKY_CFLAGS', '-Wno-error=format-truncation', testflags=True) conf.ADD_NAMED_CFLAGS('PICKY_CFLAGS', '-Wno-error=cast-qual', testflags=True) conf.ADD_NAMED_CFLAGS('PICKY_CFLAGS', '-Wno-error=format-nonliteral', testflags=True) diff --git a/lib/replace/tests/testsuite.c b/lib/replace/tests/testsuite.c index 7c9195b4753..624b1687b4f 100644 --- a/lib/replace/tests/testsuite.c +++ b/lib/replace/tests/testsuite.c @@ -380,6 +380,11 @@ static int test_asprintf(void) return true; } +/* This test explicitly triggers truncation, so we need to + * suppress the warning + */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-truncation" static int test_snprintf(void) { char tmp[10]; @@ -397,6 +402,7 @@ static int test_snprintf(void) printf("success: snprintf\n"); return true; } +#pragma GCC diagnostic pop static int test_vasprintf(void) {