]> git.neil.brown.name Git - git.git/commitdiff
archive-tar: convert snprintf to xsnprintf
authorJeff King <peff@peff.net>
Thu, 26 May 2016 04:28:08 +0000 (00:28 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 26 May 2016 17:44:26 +0000 (10:44 -0700)
Commit f2f0267 (archive-tar: use xsnprintf for trivial
formatting, 2015-09-24) converted cases of "sprintf" to
"xsnprintf", but accidentally left one as just "snprintf".
This meant that we could silently truncate the resulting
buffer instead of flagging an error.

In practice, this is impossible to achieve, as we are
formatting a ustar checksum, which can be at most 7
characters. But the point of xsnprintf is to document and
check for "should be impossible" conditions; this site was
just accidentally mis-converted during f2f0267.

Noticed-by: Paul Green <Paul.Green@stratus.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
archive-tar.c

index 501ca97760b1f62ada876d372bd1abbbc41c6cd0..cb99df28142f164da62f5a728eb9019e57804157 100644 (file)
@@ -181,7 +181,7 @@ static void prepare_header(struct archiver_args *args,
        memcpy(header->magic, "ustar", 6);
        memcpy(header->version, "00", 2);
 
-       snprintf(header->chksum, sizeof(header->chksum), "%07o", ustar_header_chksum(header));
+       xsnprintf(header->chksum, sizeof(header->chksum), "%07o", ustar_header_chksum(header));
 }
 
 static int write_extended_header(struct archiver_args *args,