git: 69c8025a4984 - main - Silence snprintf truncation warnings in printf_test examples

From: Dimitry Andric <dim_at_FreeBSD.org>
Date: Thu, 21 Dec 2023 22:46:06 UTC
The branch main has been updated by dim:

URL: https://cgit.FreeBSD.org/src/commit/?id=69c8025a498450b6bc4cc9e97ba779ed1c2e7f4b

commit 69c8025a498450b6bc4cc9e97ba779ed1c2e7f4b
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2023-12-21 22:39:15 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2023-12-21 22:45:52 +0000

    Silence snprintf truncation warnings in printf_test examples
    
    Building share/examples/tests with clang 18 results in a few warnings
    like:
    
      share/examples/tests/tests/plain/printf_test.c:67:6: error: 'snprintf' will always be truncated; specified size is 10, but format string expands to at least 17 [-Werror,-Wformat-truncation]
         67 |         if (snprintf(buffer, sizeof(buffer), "0123456789abcdef") != 16)
            |             ^
    
    Since these tests are meant as an example of testing snprintf overflow,
    suppress the warnings.
    
    MFC after:      3 days
---
 share/examples/tests/tests/atf/Makefile   | 4 ++++
 share/examples/tests/tests/plain/Makefile | 4 ++++
 share/examples/tests/tests/tap/Makefile   | 4 ++++
 3 files changed, 12 insertions(+)

diff --git a/share/examples/tests/tests/atf/Makefile b/share/examples/tests/tests/atf/Makefile
index 305d66c51f38..7614767b6e0a 100644
--- a/share/examples/tests/tests/atf/Makefile
+++ b/share/examples/tests/tests/atf/Makefile
@@ -46,3 +46,7 @@ file1:
 	@echo "File 1" > ${.TARGET}
 
 .include <bsd.test.mk>
+
+.if ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 180000
+CWARNFLAGS.printf_test.c+=	-Wno-format-truncation
+.endif
diff --git a/share/examples/tests/tests/plain/Makefile b/share/examples/tests/tests/plain/Makefile
index 2594968a6f44..462324309f6a 100644
--- a/share/examples/tests/tests/plain/Makefile
+++ b/share/examples/tests/tests/plain/Makefile
@@ -46,3 +46,7 @@ file1:
 	@echo "File 1" > ${.TARGET}
 
 .include <bsd.test.mk>
+
+.if ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 180000
+CWARNFLAGS.printf_test.c+=	-Wno-format-truncation
+.endif
diff --git a/share/examples/tests/tests/tap/Makefile b/share/examples/tests/tests/tap/Makefile
index 5b829afd5838..86d3f6805045 100644
--- a/share/examples/tests/tests/tap/Makefile
+++ b/share/examples/tests/tests/tap/Makefile
@@ -46,3 +46,7 @@ file1:
 	@echo "File 1" > ${.TARGET}
 
 .include <bsd.test.mk>
+
+.if ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 180000
+CWARNFLAGS.printf_test.c+=	-Wno-format-truncation
+.endif