]> granicus.if.org Git - git/commitdiff
sha1_name: use strlcpy() to copy strings
authorRené Scharfe <l.s.r@web.de>
Sat, 21 Feb 2015 19:55:22 +0000 (20:55 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 22 Feb 2015 20:01:38 +0000 (12:01 -0800)
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>
sha1_name.c

index 63ee66fedd617e2cacfae7a763f43ee600d15273..9ef426b32f040120071e05e52c69dbee9892e7c7 100644 (file)
@@ -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;