drop length argument of has_extension
As Fredrik points out the current interface of has_extension() is potentially confusing. Its parameters include both a nul-terminated string and a length-limited string. This patch drops the length argument, requiring two nul-terminated strings; all callsites are updated. I checked that all of them indeed provide nul-terminated strings. Filenames need to be nul-terminated anyway if they are to be passed to open() etc. The performance penalty of the additional strlen() is negligible compared to the system calls which inevitably surround has_extension() calls. Additionally, change has_extension() to use size_t inside instead of int, as that is the exact type strlen() returns and memcmp() expects. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:

committed by
Junio C Hamano

parent
ca9e3b124f
commit
5bb1cda5f7
@ -44,7 +44,7 @@ static int setup_indices(void)
|
||||
while ((de = readdir(dir)) != NULL) {
|
||||
int namelen = strlen(de->d_name);
|
||||
if (namelen != 50 ||
|
||||
!has_extension(de->d_name, namelen, ".pack"))
|
||||
!has_extension(de->d_name, ".pack"))
|
||||
continue;
|
||||
get_sha1_hex(de->d_name + 5, sha1);
|
||||
setup_index(sha1);
|
||||
|
Reference in New Issue
Block a user