]> granicus.if.org Git - zfs/commitdiff
Explicit integer promotion for bit shift operations
authorGvozden Neskovic <neskovic@gmail.com>
Fri, 2 Sep 2016 13:07:00 +0000 (15:07 +0200)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 29 Sep 2016 22:55:41 +0000 (15:55 -0700)
Explicitly promote variables to correct type. Undefined behavior is
reported because length of int is not well defined by C standard.

Issue #4883

Signed-off-by: Gvozden Neskovic <neskovic@gmail.com>
module/zfs/sha256.c
module/zfs/spa_stats.c

index cf9dd8fcba1a8eea342823345f78807a6862ad5f..57f5b7daffea0c0bfd15a3f49eb4a73404620f1e 100644 (file)
@@ -76,7 +76,8 @@ SHA256Transform(uint32_t *H, const uint8_t *cp)
        uint32_t a, b, c, d, e, f, g, h, t, T1, T2, W[64];
 
        for (t = 0; t < 16; t++, cp += 4)
-               W[t] = (cp[0] << 24) | (cp[1] << 16) | (cp[2] << 8) | cp[3];
+               W[t] = ((uint32_t)cp[0] << 24) | ((uint32_t)cp[1] << 16) |
+                   ((uint32_t)cp[2] << 8) | (uint32_t)cp[3];
 
        for (t = 16; t < 64; t++)
                W[t] = sigma1(W[t - 2]) + W[t - 7] +
index 2b8559b5d276b0c53f1ef61271bfceb66afeb8d2..c3d1c3b958dc96f2c83974fe77983c7a4936d73f 100644 (file)
@@ -600,7 +600,7 @@ spa_tx_assign_add_nsecs(spa_t *spa, uint64_t nsecs)
        spa_stats_history_t *ssh = &spa->spa_stats.tx_assign_histogram;
        uint64_t idx = 0;
 
-       while (((1 << idx) < nsecs) && (idx < ssh->size - 1))
+       while (((1ULL << idx) < nsecs) && (idx < ssh->size - 1))
                idx++;
 
        atomic_inc_64(&((kstat_named_t *)ssh->private)[idx].value.ui64);