Skip to content

Commit d12c24d

Browse files
peffgitster
authored andcommitted
daemon: use skip_prefix to avoid magic numbers
Like earlier cases, we can use skip_prefix to avoid magic numbers that must match the length of starts_with prefixes. However, the numbers are a little more complicated here, as we keep parsing past the prefix. We can solve it by keeping a running pointer as we parse; its final value is the location we want. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 97313be commit d12c24d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

daemon.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -626,15 +626,16 @@ static int execute(void)
626626

627627
for (i = 0; i < ARRAY_SIZE(daemon_service); i++) {
628628
struct daemon_service *s = &(daemon_service[i]);
629-
int namelen = strlen(s->name);
630-
if (starts_with(line, "git-") &&
631-
!strncmp(s->name, line + 4, namelen) &&
632-
line[namelen + 4] == ' ') {
629+
const char *arg;
630+
631+
if (skip_prefix(line, "git-", &arg) &&
632+
skip_prefix(arg, s->name, &arg) &&
633+
*arg++ == ' ') {
633634
/*
634635
* Note: The directory here is probably context sensitive,
635636
* and might depend on the actual service being performed.
636637
*/
637-
return run_service(line + namelen + 5, s);
638+
return run_service(arg, s);
638639
}
639640
}
640641

0 commit comments

Comments
 (0)