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>
Michael Haggerty committed
Jan 8, 2014 at 15:43 UTC
84d5633f986933d640d5dace561f46afe762d20f
1 file changed
+4
-4
refs.c
+4
-4
@@ -3367,6 +3367,7 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
3367
/* pre generate scanf formats from ref_rev_parse_rules[] */
3368
if (!nr_rules) {
3369
size_t total_len = 0;
3370
+ size_t offset = 0;
3371
3372
/* the rule list is NULL terminated, count them first */
3373
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)
3376
3377
scanf_fmts = xmalloc(nr_rules * sizeof(char *) + total_len);
3378
3378
- total_len = 0;
3379
+ offset = 0;
3380
for (i = 0; i < nr_rules; i++) {
3380
- scanf_fmts[i] = (char *)&scanf_fmts[nr_rules]
3381
- + total_len;
3381
+ scanf_fmts[i] = (char *)&scanf_fmts[nr_rules] + offset;
3382
gen_scanf_fmt(scanf_fmts[i], ref_rev_parse_rules[i]);
3383
- total_len += strlen(ref_rev_parse_rules[i]);
3383
+ offset += strlen(ref_rev_parse_rules[i]);
3384
}
3385
}
3386