pass constants as first argument to st_mult()
authorRené Scharfe <l.s.r@web.de>
Sat, 30 Jul 2016 18:18:31 +0000 (20:18 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 1 Aug 2016 21:01:03 +0000 (14:01 -0700)
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>
diffcore-rename.c
refs.c
shallow.c
index 58ac0a531be0722bc422eb008bfcb9695965996c..73d003a08ae72d0c8f18b16172bc09c86022eb8f 100644 (file)
@@ -541,7 +541,7 @@ void diffcore_rename(struct diff_options *options)
                                rename_dst_nr * rename_src_nr, 50, 1);
        }
 
-       mx = xcalloc(st_mult(num_create, NUM_CANDIDATE_PER_DST), sizeof(*mx));
+       mx = xcalloc(st_mult(NUM_CANDIDATE_PER_DST, num_create), sizeof(*mx));
        for (dst_cnt = i = 0; i < rename_dst_nr; i++) {
                struct diff_filespec *two = rename_dst[i].two;
                struct diff_score *m;
diff --git a/refs.c b/refs.c
index 814cad316384f953be975cdb711e320b4f1290d3..b4e7cac7b26d0903c4ab7361430c38232c1d5e82 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -922,7 +922,7 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
                        /* -2 for strlen("%.*s") - strlen("%s"); +1 for NUL */
                        total_len += strlen(ref_rev_parse_rules[nr_rules]) - 2 + 1;
 
-               scanf_fmts = xmalloc(st_add(st_mult(nr_rules, sizeof(char *)), total_len));
+               scanf_fmts = xmalloc(st_add(st_mult(sizeof(char *), nr_rules), total_len));
 
                offset = 0;
                for (i = 0; i < nr_rules; i++) {
index 4d554caf8d751d7a7c8a3a4286a208e0959ab513..54e2db73349ef22d644552c6b122ae5ed6ba2ce1 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -389,7 +389,7 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1,
        unsigned int i, nr;
        struct commit_list *head = NULL;
        int bitmap_nr = (info->nr_bits + 31) / 32;
-       size_t bitmap_size = st_mult(bitmap_nr, sizeof(uint32_t));
+       size_t bitmap_size = st_mult(sizeof(uint32_t), bitmap_nr);
        uint32_t *tmp = xmalloc(bitmap_size); /* to be freed before return */
        uint32_t *bitmap = paint_alloc(info);
        struct commit *c = lookup_commit_reference_gently(sha1, 1);