summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-09-24 17:08:03 -0400
committerJunio C Hamano <gitster@pobox.com>2015-10-05 11:08:05 -0700
commitd59f765ac9b3d6fc2e6bea262222b80493055f12 (patch)
tree1909246830533d821b2e68dcca43fd5b15cccdad /diff.c
parentf063d38b808e184675e5b0931ea0167a013b3fcb (diff)
downloadgit-d59f765ac9b3d6fc2e6bea262222b80493055f12.tar.gz
use sha1_to_hex_r() instead of strcpy
Before sha1_to_hex_r() existed, a simple way to get hex sha1 into a buffer was with: strcpy(buf, sha1_to_hex(sha1)); This isn't wrong (assuming the buf is 41 characters), but it makes auditing the code base for bad strcpy() calls harder, as these become false positives. Let's convert them to sha1_to_hex_r(), and likewise for some calls to find_unique_abbrev(). While we're here, we'll double-check that all of the buffers are correctly sized, and use the more obvious GIT_SHA1_HEXSZ constant. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/diff.c b/diff.c
index 788e371dec..2a37378ec8 100644
--- a/diff.c
+++ b/diff.c
@@ -322,7 +322,7 @@ static struct diff_tempfile {
*/
const char *name;
- char hex[41];
+ char hex[GIT_SHA1_HEXSZ + 1];
char mode[10];
/*
@@ -2878,8 +2878,7 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
die_errno("unable to write temp-file");
close_tempfile(&temp->tempfile);
temp->name = get_tempfile_path(&temp->tempfile);
- strcpy(temp->hex, sha1_to_hex(sha1));
- temp->hex[40] = 0;
+ sha1_to_hex_r(temp->hex, sha1);
xsnprintf(temp->mode, sizeof(temp->mode), "%06o", mode);
strbuf_release(&buf);
strbuf_release(&template);
@@ -2926,9 +2925,9 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
/* we can borrow from the file in the work tree */
temp->name = name;
if (!one->sha1_valid)
- strcpy(temp->hex, sha1_to_hex(null_sha1));
+ sha1_to_hex_r(temp->hex, null_sha1);
else
- strcpy(temp->hex, sha1_to_hex(one->sha1));
+ sha1_to_hex_r(temp->hex, one->sha1);
/* Even though we may sometimes borrow the
* contents from the work tree, we always want
* one->mode. mode is trustworthy even when