[PATCH v2] Hide memset/bzero from compiler
H.J. Lu
hjl.tools@gmail.com
Tue Dec 17 18:38:26 GMT 2024
Hide memset/bzero from compiler to silence Clang error:
./tester.c:1345:29: error: 'size' argument to memset is '0'; did you mean to transpose the last two arguments? [-Werror,-Wmemset-transposed-args]
1345 | (void) memset(one+2, 'y', 0);
| ^
./tester.c:1345:29: note: parenthesize the third argument to silence
./tester.c:1432:16: error: 'size' argument to bzero is '0' [-Werror,-Wsuspicious-bzero]
1432 | bzero(one+2, 0);
| ^
./tester.c:1432:16: note: parenthesize the second argument to silence
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
string/tester.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/string/tester.c b/string/tester.c
index ee96747280..3e3660777e 100644
--- a/string/tester.c
+++ b/string/tester.c
@@ -50,6 +50,15 @@ DIAG_IGNORE_NEEDS_COMMENT (11, "-Wstringop-overread");
#include <strings.h>
#include <fcntl.h>
+static __typeof (bzero) * volatile bzero_indirect = bzero;
+static __typeof (memset) * volatile memset_indirect = memset;
+
+#undef bzero
+#undef memset
+
+#define bzero bzero_indirect
+#define memset memset_indirect
+
/* This file tests a range of corner cases of string functions,
including cases where truncation occurs or where sizes specified
are larger than the actual buffers, which result in various
--
2.47.1
More information about the Libc-alpha
mailing list