summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Michael Haggerty <mhagger@alum.mit.edu>2014-01-08 15:43:40 +0100
committerLibravatar Junio C Hamano <gitster@pobox.com>2014-01-09 15:02:36 -0800
commit7902fe03f97e2e74f95c96b8d18a7752bbb2ef6a (patch)
treef874c25910237497de94f8d42da92b9c5515dc1c
parentgen_scanf_fmt(): delete function and use snprintf() instead (diff)
downloadtgif-7902fe03f97e2e74f95c96b8d18a7752bbb2ef6a.tar.xz
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 <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--refs.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/refs.c b/refs.c
index 5e54af267a..676bfd550e 100644
--- a/refs.c
+++ b/refs.c
@@ -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);