Skip to content

Commit 7902fe0

Browse files
mhaggergitster
authored andcommitted
shorten_unambiguous_ref(): tighten up pointer arithmetic
As long as we're being pathologically stingy with mallocs, we might as well do the math right and save 6 (!) bytes. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4346663 commit 7902fe0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

refs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3353,8 +3353,8 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
33533353

33543354
/* the rule list is NULL terminated, count them first */
33553355
for (nr_rules = 0; ref_rev_parse_rules[nr_rules]; nr_rules++)
3356-
/* no +1 because strlen("%s") < strlen("%.*s") */
3357-
total_len += strlen(ref_rev_parse_rules[nr_rules]);
3356+
/* -2 for strlen("%.*s") - strlen("%s"); +1 for NUL */
3357+
total_len += strlen(ref_rev_parse_rules[nr_rules]) - 2 + 1;
33583358

33593359
scanf_fmts = xmalloc(nr_rules * sizeof(char *) + total_len);
33603360

0 commit comments

Comments
 (0)