summaryrefslogtreecommitdiff
path: root/sha1_name.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2015-02-21 19:55:22 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-02-22 20:01:38 (GMT)
commit2ce63e9fac242a70cd6d9e1325063bbb2e5091f8 (patch)
tree3eb4d08d659499ec4781e3eb3f42c491cb9439f8 /sha1_name.c
parent68d6d6eb402d7e39c89ce43ca37e6c16b941890c (diff)
downloadgit-2ce63e9fac242a70cd6d9e1325063bbb2e5091f8.zip
git-2ce63e9fac242a70cd6d9e1325063bbb2e5091f8.tar.gz
git-2ce63e9fac242a70cd6d9e1325063bbb2e5091f8.tar.bz2
sha1_name: use strlcpy() to copy strings
Use strlcpy() instead of calling strncpy() and then setting the last byte of the target buffer to NUL explicitly. This shortens and simplifies the code a bit. Signed-of-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_name.c')
-rw-r--r--sha1_name.c8
1 files changed, 2 insertions, 6 deletions
diff --git a/sha1_name.c b/sha1_name.c
index 63ee66f..9ef426b 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -1384,9 +1384,7 @@ static int get_sha1_with_context_1(const char *name,
namelen = strlen(cp);
}
- strncpy(oc->path, cp,
- sizeof(oc->path));
- oc->path[sizeof(oc->path)-1] = '\0';
+ strlcpy(oc->path, cp, sizeof(oc->path));
if (!active_cache)
read_cache();
@@ -1436,9 +1434,7 @@ static int get_sha1_with_context_1(const char *name,
name, len);
}
hashcpy(oc->tree, tree_sha1);
- strncpy(oc->path, filename,
- sizeof(oc->path));
- oc->path[sizeof(oc->path)-1] = '\0';
+ strlcpy(oc->path, filename, sizeof(oc->path));
free(new_filename);
return ret;