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>
This commit is contained in:
parent
68d6d6eb40
commit
2ce63e9fac
@ -1384,9 +1384,7 @@ static int get_sha1_with_context_1(const char *name,
|
|||||||
namelen = strlen(cp);
|
namelen = strlen(cp);
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(oc->path, cp,
|
strlcpy(oc->path, cp, sizeof(oc->path));
|
||||||
sizeof(oc->path));
|
|
||||||
oc->path[sizeof(oc->path)-1] = '\0';
|
|
||||||
|
|
||||||
if (!active_cache)
|
if (!active_cache)
|
||||||
read_cache();
|
read_cache();
|
||||||
@ -1436,9 +1434,7 @@ static int get_sha1_with_context_1(const char *name,
|
|||||||
name, len);
|
name, len);
|
||||||
}
|
}
|
||||||
hashcpy(oc->tree, tree_sha1);
|
hashcpy(oc->tree, tree_sha1);
|
||||||
strncpy(oc->path, filename,
|
strlcpy(oc->path, filename, sizeof(oc->path));
|
||||||
sizeof(oc->path));
|
|
||||||
oc->path[sizeof(oc->path)-1] = '\0';
|
|
||||||
|
|
||||||
free(new_filename);
|
free(new_filename);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user