Skip to content

Commit

Permalink
sha1_name: use strlcpy() to copy strings
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed Feb 22, 2015
1 parent 68d6d6e commit 2ce63e9
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions sha1_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2ce63e9

Please sign in to comment.