From cbadf0ee37def5cea81fb7702941af8234dd094d Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 14 Feb 2018 13:06:57 -0500 Subject: [PATCH] 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 Signed-off-by: Junio C Hamano --- t/helper/test-hashmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/helper/test-hashmap.c b/t/helper/test-hashmap.c index 2100877c2b..28b913fbd6 100644 --- a/t/helper/test-hashmap.c +++ b/t/helper/test-hashmap.c @@ -87,7 +87,7 @@ static void perf_hashmap(unsigned int method, unsigned int rounds) ALLOC_ARRAY(entries, TEST_SIZE); ALLOC_ARRAY(hashes, TEST_SIZE); for (i = 0; i < TEST_SIZE; i++) { - snprintf(buf, sizeof(buf), "%i", i); + xsnprintf(buf, sizeof(buf), "%i", i); entries[i] = alloc_test_entry(0, buf, strlen(buf), "", 0); hashes[i] = hash(method, i, entries[i]->key); }