rcuja: fix 8-bit overflow in 1d/2d distribution sum
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 6 Jun 2013 16:43:59 +0000 (12:43 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 6 Jun 2013 16:43:59 +0000 (12:43 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
rcuja/rcuja.c

index a608dd7c4797e534339f64ab841c054492f7e00e..22ee01cef781e3977ba4884538b66a08697b633a 100644 (file)
@@ -1032,7 +1032,7 @@ unsigned int ja_node_sum_distribution_1d(enum ja_recompact mode,
        for (bit_i = 0; bit_i < JA_BITS_PER_BYTE; bit_i++) {
                unsigned int distance_to_best;
 
-               distance_to_best = abs_int((nr_one[bit_i] << 1U) - distrib_nr_child);
+               distance_to_best = abs_int(((unsigned int) nr_one[bit_i] << 1U) - distrib_nr_child);
                if (distance_to_best < overall_best_distance) {
                        overall_best_distance = distance_to_best;
                        bitsel = bit_i;
@@ -1228,10 +1228,10 @@ void ja_node_sum_distribution_2d(enum ja_recompact mode,
                for (bit_j = 0; bit_j < bit_i; bit_j++) {
                        int distance_to_best[4];
 
-                       distance_to_best[0] = (nr_2d_11[bit_i][bit_j] << 2U) - distrib_nr_child;
-                       distance_to_best[1] = (nr_2d_10[bit_i][bit_j] << 2U) - distrib_nr_child;
-                       distance_to_best[2] = (nr_2d_01[bit_i][bit_j] << 2U) - distrib_nr_child;
-                       distance_to_best[3] = (nr_2d_00[bit_i][bit_j] << 2U) - distrib_nr_child;
+                       distance_to_best[0] = ((unsigned int) nr_2d_11[bit_i][bit_j] << 2U) - distrib_nr_child;
+                       distance_to_best[1] = ((unsigned int) nr_2d_10[bit_i][bit_j] << 2U) - distrib_nr_child;
+                       distance_to_best[2] = ((unsigned int) nr_2d_01[bit_i][bit_j] << 2U) - distrib_nr_child;
+                       distance_to_best[3] = ((unsigned int) nr_2d_00[bit_i][bit_j] << 2U) - distrib_nr_child;
 
                        /* Consider worse distance above best */
                        if (distance_to_best[1] > 0 && distance_to_best[1] > distance_to_best[0])
This page took 0.027803 seconds and 4 git commands to generate.