Skip to content

Commit 614b195

Browse files
peffgitster
authored andcommitted
fast-import: use xsnprintf for writing sha1s
When we have to write a sha1 with a newline, we do so by copying both into a single buffer, so that we can issue a single write() call. We use snprintf but don't bother to check the output, since we know it will fit. However, we should use xsnprintf() in such a case so that we're notified if our assumption turns out to be wrong (and to make it easier to audit for unchecked snprintf calls). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 296ab78 commit 614b195

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fast-import.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3003,7 +3003,7 @@ static void parse_get_mark(const char *p)
30033003
if (!oe)
30043004
die("Unknown mark: %s", command_buf.buf);
30053005

3006-
snprintf(output, sizeof(output), "%s\n", sha1_to_hex(oe->idx.sha1));
3006+
xsnprintf(output, sizeof(output), "%s\n", sha1_to_hex(oe->idx.sha1));
30073007
cat_blob_write(output, 41);
30083008
}
30093009

0 commit comments

Comments
 (0)