diff options
author | Jeff King <peff@peff.net> | 2018-02-14 18:06:57 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-02-14 18:31:09 (GMT) |
commit | cbadf0ee37def5cea81fb7702941af8234dd094d (patch) | |
tree | 82d6e0192f6aefe2ea6e5a0856dc4a00b6172d77 /t/helper/test-hashmap.c | |
parent | b6c4380d6e3170e21e6670248b7f332c57cb077c (diff) | |
download | git-cbadf0ee37def5cea81fb7702941af8234dd094d.zip git-cbadf0ee37def5cea81fb7702941af8234dd094d.tar.gz git-cbadf0ee37def5cea81fb7702941af8234dd094d.tar.bz2 |
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/helper/test-hashmap.c')
-rw-r--r-- | t/helper/test-hashmap.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/t/helper/test-hashmap.c b/t/helper/test-hashmap.c index 2100877..28b913f 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); } |