Commit 1bf57b5a34ac535a94a55cdd40a6abb2f26c78a8

Patrick Steinhardt 2018-05-04T15:27:11

tests: iterator::workdir: fix GCC warning Since GCC 8.1, the compiler performs some bounds checking when copying static data into arrays with a known size. In one test, we print a format string of "%s/sub%02d" into a buffer of 64 bytes. The input buffer for the first "%s" is bounded to at most 63 characters, plus four bytes for the static string "/sub" plus two more bytes for "%02d". Thus, our target buffer needs to be at least 70 bytes in size, including the NUL byte. There seems to be a bug in the analysis, though, because GCC will not account for the limiting "%02" prefix, treating it as requiring the same count of bytes as a "%d". Thus, we end up at 79 bytes that are required to fix the warning. To make it look nicer and less special, we just round the buffer size up to 80 bytes.

1
2
3
4
5
6
7
8
9
10
11
12
13
diff --git a/tests/iterator/workdir.c b/tests/iterator/workdir.c
index 8101675..c38a615 100644
--- a/tests/iterator/workdir.c
+++ b/tests/iterator/workdir.c
@@ -460,7 +460,7 @@ void test_iterator_workdir__icase_starts_and_ends(void)
 static void build_workdir_tree(const char *root, int dirs, int subs)
 {
 	int i, j;
-	char buf[64], sub[64];
+	char buf[64], sub[80];
 
 	for (i = 0; i < dirs; ++i) {
 		if (i % 2 == 0) {