From d0b51f93d00c600d2c2e5480b1fd1d8d32bb1fdc Mon Sep 17 00:00:00 2001
From: Tharre <tharre3@gmail.com>
Date: Wed, 26 Oct 2016 00:46:05 +0200
Subject: Make sha1_to_hex() return a null-terminated string

---
 src/build.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

(limited to 'src')

diff --git a/src/build.c b/src/build.c
index bd4da3c..db73d4a 100644
--- a/src/build.c
+++ b/src/build.c
@@ -404,6 +404,7 @@ static void update_dep_info(dep_info *dep, const char *target) {
 	fclose(fp);
 }
 
+/* Requires a buffer of at least 20*2+1 = 41 bytes */
 static void sha1_to_hex(const unsigned char *sha1, char *buf) {
 	static const char hex[] = "0123456789abcdef";
 
@@ -412,6 +413,8 @@ static void sha1_to_hex(const unsigned char *sha1, char *buf) {
 		*pos++ = hex[sha1[i] >> 4];
 		*pos = hex[sha1[i] & 0xf];
 	}
+
+	buf[40] = '\0';
 }
 
 static void hex_to_sha1(const char *s, unsigned char *sha1) {
@@ -429,7 +432,6 @@ static void write_dep_information(dep_info *dep) {
 
 	char hash[41];
 	sha1_to_hex(dep->hash, hash);
-	hash[40] = '\0';
 	char *flags = dep->flags & DEP_SOURCE ? "s" : "l";
 
 	int magic = atoi(getenv("REDO_MAGIC"));
-- 
cgit v1.2.3-70-g09d2