summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-05-04 15:27:11 +0200
committerPatrick Steinhardt <ps@pks.im>2018-05-04 15:27:25 +0200
commit1bf57b5a34ac535a94a55cdd40a6abb2f26c78a8 (patch)
treea92cc19b18bffae0ae944582e8d0a833531bcaa6
parent0750d0cc5b449c5545fcc0099df6737f63e32a19 (diff)
downloadlibgit2-1bf57b5a34ac535a94a55cdd40a6abb2f26c78a8.tar.gz
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.
-rw-r--r--tests/iterator/workdir.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/tests/iterator/workdir.c b/tests/iterator/workdir.c
index 81016752c..c38a6152b 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) {