summaryrefslogtreecommitdiff
path: root/fast-import.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-09-24 21:08:19 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-10-05 18:08:05 (GMT)
commit34fa79a6cde56d6d428ab0d3160cb094ebad3305 (patch)
treed75524981f407be8af783b743df86f4a0e757d0e /fast-import.c
parent4c9ac3bfaad9e32a7a98178d1f01779a3698144f (diff)
downloadgit-34fa79a6cde56d6d428ab0d3160cb094ebad3305.zip
git-34fa79a6cde56d6d428ab0d3160cb094ebad3305.tar.gz
git-34fa79a6cde56d6d428ab0d3160cb094ebad3305.tar.bz2
prefer memcpy to strcpy
When we already know the length of a string (e.g., because we just malloc'd to fit it), it's nicer to use memcpy than strcpy, as it makes it more obvious that we are not going to overflow the buffer (because the size we pass matches the size in the allocation). This also eliminates calls to strcpy, which make auditing the code base harder. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'fast-import.c')
-rw-r--r--fast-import.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/fast-import.c b/fast-import.c
index 895c6b4..cf6d8bc 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -644,8 +644,9 @@ static void *pool_calloc(size_t count, size_t size)
static char *pool_strdup(const char *s)
{
- char *r = pool_alloc(strlen(s) + 1);
- strcpy(r, s);
+ size_t len = strlen(s) + 1;
+ char *r = pool_alloc(len);
+ memcpy(r, s, len);
return r;
}