Commit 0750d0cc5b449c5545fcc0099df6737f63e32a19

Patrick Steinhardt 2018-05-04T15:25:22

tests: refs::normalize: simplify code to avoid GCC warning Since version 8.1, GCC will do some automatic bounds checking when printing static content into a buffer with known size. The bounds checking doesn't yet work quite right in all scenarios and may thus lead to false positives. Fix one of these false positives in refs::normalize by simplifying the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
diff --git a/tests/refs/normalize.c b/tests/refs/normalize.c
index 7f313ef..f9c525e 100644
--- a/tests/refs/normalize.c
+++ b/tests/refs/normalize.c
@@ -193,10 +193,7 @@ void test_refs_normalize__jgit_suite(void)
 		char c;
 		char buffer[GIT_REFNAME_MAX];
 		for (c = '\1'; c < ' '; c++) {
-			strncpy(buffer, "refs/heads/mast", 15);
-			strncpy(buffer + 15, (const char *)&c, 1);
-			strncpy(buffer + 16, "er", 2);
-			buffer[18 - 1] = '\0';
+			p_snprintf(buffer, sizeof(buffer), "refs/heads/mast%cer", c);
 			ensure_refname_invalid(GIT_REF_FORMAT_ALLOW_ONELEVEL, buffer);
 		}
 	}