use strchrnul() in place of strchr() and strlen()
Avoid scanning strings twice, once with strchr() and then with strlen(), by using strchrnul(). Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Rohit Mani <rohit.mani@outlook.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
5f95c9f850
commit
2c5495f7b6
@ -259,8 +259,8 @@ static void parse_treeish_arg(const char **argv,
|
||||
/* Remotes are only allowed to fetch actual refs */
|
||||
if (remote) {
|
||||
char *ref = NULL;
|
||||
const char *colon = strchr(name, ':');
|
||||
int refnamelen = colon ? colon - name : strlen(name);
|
||||
const char *colon = strchrnul(name, ':');
|
||||
int refnamelen = colon - name;
|
||||
|
||||
if (!dwim_ref(name, refnamelen, sha1, &ref))
|
||||
die("no such ref: %.*s", refnamelen, name);
|
||||
|
||||
Reference in New Issue
Block a user