summaryrefslogtreecommitdiff
path: root/compat/nedmalloc/nedmalloc.c
diff options
context:
space:
mode:
authorLibravatar Jeff King <peff@peff.net>2015-09-24 17:08:19 -0400
committerLibravatar Junio C Hamano <gitster@pobox.com>2015-10-05 11:08:05 -0700
commit34fa79a6cde56d6d428ab0d3160cb094ebad3305 (patch)
treed75524981f407be8af783b743df86f4a0e757d0e /compat/nedmalloc/nedmalloc.c
parenthelp: clean up kfmclient munging (diff)
downloadtgif-34fa79a6cde56d6d428ab0d3160cb094ebad3305.tar.xz
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 'compat/nedmalloc/nedmalloc.c')
-rw-r--r--compat/nedmalloc/nedmalloc.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/compat/nedmalloc/nedmalloc.c b/compat/nedmalloc/nedmalloc.c
index 609ebba125..a0a16eb1bb 100644
--- a/compat/nedmalloc/nedmalloc.c
+++ b/compat/nedmalloc/nedmalloc.c
@@ -957,8 +957,9 @@ char *strdup(const char *s1)
{
char *s2 = 0;
if (s1) {
- s2 = malloc(strlen(s1) + 1);
- strcpy(s2, s1);
+ size_t len = strlen(s1) + 1;
+ s2 = malloc(len);
+ memcpy(s2, s1, len);
}
return s2;
}