Skip to content

Commit 84d5633

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c90d3db commit 84d5633

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

refs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3367,6 +3367,7 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
33673367
/* pre generate scanf formats from ref_rev_parse_rules[] */
33683368
if (!nr_rules) {
33693369
size_t total_len = 0;
3370+
size_t offset = 0;
33703371

33713372
/* the rule list is NULL terminated, count them first */
33723373
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)
33753376

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

3378-
total_len = 0;
3379+
offset = 0;
33793380
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;
33823382
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]);
33843384
}
33853385
}
33863386

0 commit comments

Comments
 (0)