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>
René Scharfe committed
Feb 21, 2015 at 20:55 UTC
2ce63e9fac242a70cd6d9e1325063bbb2e5091f8
1 file changed
+2
-6
sha1_name.c
+2
-6
@@ -1384,9 +1384,7 @@ static int get_sha1_with_context_1(const char *name,
1384
namelen = strlen(cp);
1385
}
1386
1387
- strncpy(oc->path, cp,
1388
- sizeof(oc->path));
1389
- oc->path[sizeof(oc->path)-1] = '\0';
1387
+ strlcpy(oc->path, cp, sizeof(oc->path));
1388
1389
if (!active_cache)
1390
read_cache();
@@ -1436,9 +1434,7 @@ static int get_sha1_with_context_1(const char *name,
1434
name, len);
1435
}
1436
hashcpy(oc->tree, tree_sha1);
1439
- strncpy(oc->path, filename,
1440
- sizeof(oc->path));
1441
- oc->path[sizeof(oc->path)-1] = '\0';
1437
+ strlcpy(oc->path, filename, sizeof(oc->path));
1438
1439
free(new_filename);
1440
return ret;