test-hashmap: use xsnprintf rather than snprintf

In general, using a bare snprintf can truncate the resulting buffer, leading to confusing results. In this case we know that our buffer is sized large enough to accommodate our loop, so there's no bug. However, we should use xsnprintf() to document (and check) that assumption, and to model good practice to people reading the code. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Feb 14, 2018 at 13:06 UTC cbadf0ee37def5cea81fb7702941af8234dd094d
1 file changed +1 -1
t/helper/test-hashmap.c
+1 -1
@@ -87,7 +87,7 @@ static void perf_hashmap(unsigned int method, unsigned int rounds)
87 ALLOC_ARRAY(entries, TEST_SIZE);
88 ALLOC_ARRAY(hashes, TEST_SIZE);
89 for (i = 0; i < TEST_SIZE; i++) {
90 - snprintf(buf, sizeof(buf), "%i", i);
90 + xsnprintf(buf, sizeof(buf), "%i", i);
91 entries[i] = alloc_test_entry(0, buf, strlen(buf), "", 0);
92 hashes[i] = hash(method, i, entries[i]->key);
93 }