pass constants as first argument to st_mult()
The result of st_mult() is the same no matter the order of its arguments. It invokes the macro unsigned_mult_overflows(), which divides the second parameter by the first one. Pass constants first to allow that division to be done already at compile time. Signed-off-by: Rene Scharfe <l.s.r@web.de> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Jul 30, 2016 at 20:18 UTC
50492f7b38f84619cbfb443efc3c0c78fc0304dd
3 files changed
+3
-3
diffcore-rename.c
+1
-1
@@ -541,7 +541,7 @@ void diffcore_rename(struct diff_options *options)
541
rename_dst_nr * rename_src_nr, 50, 1);
542
}
543
544
- mx = xcalloc(st_mult(num_create, NUM_CANDIDATE_PER_DST), sizeof(*mx));
544
+ mx = xcalloc(st_mult(NUM_CANDIDATE_PER_DST, num_create), sizeof(*mx));
545
for (dst_cnt = i = 0; i < rename_dst_nr; i++) {
546
struct diff_filespec *two = rename_dst[i].two;
547
struct diff_score *m;
refs.c
+1
-1
@@ -922,7 +922,7 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
922
/* -2 for strlen("%.*s") - strlen("%s"); +1 for NUL */
923
total_len += strlen(ref_rev_parse_rules[nr_rules]) - 2 + 1;
924
925
- scanf_fmts = xmalloc(st_add(st_mult(nr_rules, sizeof(char *)), total_len));
925
+ scanf_fmts = xmalloc(st_add(st_mult(sizeof(char *), nr_rules), total_len));
926
927
offset = 0;
928
for (i = 0; i < nr_rules; i++) {
shallow.c
+1
-1
@@ -389,7 +389,7 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1,
389
unsigned int i, nr;
390
struct commit_list *head = NULL;
391
int bitmap_nr = (info->nr_bits + 31) / 32;
392
- size_t bitmap_size = st_mult(bitmap_nr, sizeof(uint32_t));
392
+ size_t bitmap_size = st_mult(sizeof(uint32_t), bitmap_nr);
393
uint32_t *tmp = xmalloc(bitmap_size); /* to be freed before return */
394
uint32_t *bitmap = paint_alloc(info);
395
struct commit *c = lookup_commit_reference_gently(sha1, 1);