Skip to content

Commit 2ce63e9

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 68d6d6e commit 2ce63e9

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

sha1_name.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,9 +1384,7 @@ static int get_sha1_with_context_1(const char *name,
13841384
namelen = strlen(cp);
13851385
}
13861386

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));
13901388

13911389
if (!active_cache)
13921390
read_cache();
@@ -1436,9 +1434,7 @@ static int get_sha1_with_context_1(const char *name,
14361434
name, len);
14371435
}
14381436
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));
14421438

14431439
free(new_filename);
14441440
return ret;

0 commit comments

Comments
 (0)