summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorLibravatar Michael Haggerty <mhagger@alum.mit.edu>2014-01-08 15:43:38 +0100
committerLibravatar Junio C Hamano <gitster@pobox.com>2014-01-09 14:52:44 -0800
commit84d5633f986933d640d5dace561f46afe762d20f (patch)
tree56b3202dd8bd679a6e350fc5fee58672045c08a0 /refs.c
parentMerge branch 'maint' of git://github.com/git-l10n/git-po into maint (diff)
downloadtgif-84d5633f986933d640d5dace561f46afe762d20f.tar.xz
shorten_unambiguous_ref(): introduce a new local variable
When filling the scanf_fmts array, use a separate variable to keep track of the offset to avoid clobbering total_len (which we will need in the next commit). Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/refs.c b/refs.c
index 5e5a3824b9..7ac3043f88 100644
--- a/refs.c
+++ b/refs.c
@@ -3367,6 +3367,7 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
/* pre generate scanf formats from ref_rev_parse_rules[] */
if (!nr_rules) {
size_t total_len = 0;
+ size_t offset = 0;
/* the rule list is NULL terminated, count them first */
for (nr_rules = 0; ref_rev_parse_rules[nr_rules]; nr_rules++)
@@ -3375,12 +3376,11 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
scanf_fmts = xmalloc(nr_rules * sizeof(char *) + total_len);
- total_len = 0;
+ offset = 0;
for (i = 0; i < nr_rules; i++) {
- scanf_fmts[i] = (char *)&scanf_fmts[nr_rules]
- + total_len;
+ scanf_fmts[i] = (char *)&scanf_fmts[nr_rules] + offset;
gen_scanf_fmt(scanf_fmts[i], ref_rev_parse_rules[i]);
- total_len += strlen(ref_rev_parse_rules[i]);
+ offset += strlen(ref_rev_parse_rules[i]);
}
}