diff options
author | René Scharfe <l.s.r@web.de> | 2015-02-21 20:55:22 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-02-22 12:01:38 -0800 |
commit | 2ce63e9fac242a70cd6d9e1325063bbb2e5091f8 (patch) | |
tree | 3eb4d08d659499ec4781e3eb3f42c491cb9439f8 | |
parent | 68d6d6eb402d7e39c89ce43ca37e6c16b941890c (diff) | |
download | git-2ce63e9fac242a70cd6d9e1325063bbb2e5091f8.tar.gz |
sha1_name: use strlcpy() to copy stringsrs/simple-cleanups
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>
-rw-r--r-- | sha1_name.c | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/sha1_name.c b/sha1_name.c index 63ee66fedd..9ef426b32f 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; |