Skip to content

Commit cbadf0e

Browse files
peffgitster
authored andcommitted
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>
1 parent b6c4380 commit cbadf0e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

t/helper/test-hashmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static void perf_hashmap(unsigned int method, unsigned int rounds)
8787
ALLOC_ARRAY(entries, TEST_SIZE);
8888
ALLOC_ARRAY(hashes, TEST_SIZE);
8989
for (i = 0; i < TEST_SIZE; i++) {
90-
snprintf(buf, sizeof(buf), "%i", i);
90+
xsnprintf(buf, sizeof(buf), "%i", i);
9191
entries[i] = alloc_test_entry(0, buf, strlen(buf), "", 0);
9292
hashes[i] = hash(method, i, entries[i]->key);
9393
}

0 commit comments

Comments
 (0)