Skip to content

Commit 1e80e04

Browse files
dschoJunio C Hamano
authored andcommitted
sha1_to_hex: properly terminate the SHA1
sha1_to_hex() returns a pointer to a static buffer. Some of its users modify that buffer by appending a newline character. Other users rely on the fact that you can call printf("%s", sha1_to_hex(sha1)); Just to be on the safe side, terminate the SHA1 in sha1_to_hex(). Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent a14c225 commit 1e80e04

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

sha1_file.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ char * sha1_to_hex(const unsigned char *sha1)
8181
*buf++ = hex[val >> 4];
8282
*buf++ = hex[val & 0xf];
8383
}
84+
*buf = '\0';
85+
8486
return buffer;
8587
}
8688

0 commit comments

Comments
 (0)