Skip to content

Commit 1bf57b5

Browse files
committed
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 parent 0750d0c commit 1bf57b5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tests/iterator/workdir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ void test_iterator_workdir__icase_starts_and_ends(void)
460460
static void build_workdir_tree(const char *root, int dirs, int subs)
461461
{
462462
int i, j;
463-
char buf[64], sub[64];
463+
char buf[64], sub[80];
464464

465465
for (i = 0; i < dirs; ++i) {
466466
if (i % 2 == 0) {

0 commit comments

Comments
 (0)