path: root/builtin
diff options
authorJeff King <>2015-09-24 21:08:26 (GMT)
committerJunio C Hamano <>2015-10-05 18:08:06 (GMT)
commiteddda371449ba925d91d04c615d084adf1b43a33 (patch)
treea19c2df8b4502c0191e5261ca12ea5d0c6f8601a /builtin
parent02e32b7debbcbe5910c11a515801751b349577d7 (diff)
convert strncpy to memcpy
strncpy is known to be a confusing function because of its termination semantics. These calls are all correct, but it takes some examination to see why. In particular, every one of them expects to copy up to the length limit, and then makes some arrangement for terminating the result. We can just use memcpy, along with noting explicitly how the result is terminated (if it is not already obvious). That should make it more clear to a reader that we are doing the right thing. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin')
1 files changed, 2 insertions, 2 deletions
diff --git a/builtin/help.c b/builtin/help.c
index e1650ab..1cd0c1e 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -176,7 +176,7 @@ static void add_man_viewer(const char *name)
while (*p)
p = &((*p)->next);
*p = xcalloc(1, (sizeof(**p) + len + 1));
- strncpy((*p)->name, name, len);
+ memcpy((*p)->name, name, len); /* NUL-terminated by xcalloc */
static int supported_man_viewer(const char *name, size_t len)
@@ -192,7 +192,7 @@ static void do_add_man_viewer_info(const char *name,
struct man_viewer_info_list *new = xcalloc(1, sizeof(*new) + len + 1);
- strncpy(new->name, name, len);
+ memcpy(new->name, name, len); /* NUL-terminated by xcalloc */
new->info = xstrdup(value);
new->next = man_viewer_info_list;
man_viewer_info_list = new;