summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorLibravatar Jeff King <peff@peff.net>2018-02-14 13:06:57 -0500
committerLibravatar Junio C Hamano <gitster@pobox.com>2018-02-14 10:31:09 -0800
commitcbadf0ee37def5cea81fb7702941af8234dd094d (patch)
tree82d6e0192f6aefe2ea6e5a0856dc4a00b6172d77 /t
parenttest-hashmap: check allocation computation for overflow (diff)
downloadtgif-cbadf0ee37def5cea81fb7702941af8234dd094d.tar.xz
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>
Diffstat (limited to 't')
-rw-r--r--t/helper/test-hashmap.c2
1 files changed, 1 insertions, 1 deletions
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);
}