Skip to content

Commit

Permalink
shorten_unambiguous_ref(): tighten up pointer arithmetic
Browse files Browse the repository at this point in the history
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 <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Michael Haggerty authored and Junio C Hamano committed Jan 9, 2014
1 parent 4346663 commit 7902fe0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3353,8 +3353,8 @@ char *shorten_unambiguous_ref(const char *refname, int strict)

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

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

Expand Down

0 comments on commit 7902fe0

Please sign in to comment.