]> the.earth.li Git - onak.git/commitdiff
Clean up use of shifts beyond composite types
authorJonathan McDowell <noodles@earth.li>
Mon, 19 Aug 2019 06:28:16 +0000 (07:28 +0100)
committerJonathan McDowell <noodles@earth.li>
Mon, 19 Aug 2019 06:28:16 +0000 (07:28 +0100)
GCC with the -fsanitize=undefined flag issues complaints like:

runtime error: left shift of 232 by 24 places cannot be represented in
type 'int'

due to the fact we shift the byte values into a 64 bit value. Rather
than adding lots of casts split out the formation into a set of steps
that doesn't end up shifting the byte value, just the final 64 bit
value.

keydb_db4.c
keydb_fs.c

index df07769ee224030291e831f034d1e3e4696e7d55..d1947fea5869a7f338cb06484c32ebe5eb016259 100644 (file)
@@ -72,10 +72,13 @@ DB *keydb_fp(struct onak_db4_dbctx *privctx, struct openpgp_fingerprint *fp)
 {
        uint64_t keytrun;
 
-       keytrun = (fp->fp[4] << 24) |
-                       (fp->fp[5] << 16) |
-                       (fp->fp[6] <<  8) |
-                       (fp->fp[7]);
+       keytrun = fp->fp[4];
+       keytrun <<= 8;
+       keytrun |= fp->fp[5];
+       keytrun <<= 8;
+       keytrun |= fp->fp[6];
+       keytrun <<= 8;
+       keytrun |= fp->fp[7];
 
        return(privctx->dbconns[keytrun % privctx->numdbs]);
 }
index aabb616e7efcd9e3dd82ab567708e8b31e7fb5a8..f8d55dc8233dd80a2b92e6878abee3719dc67cd0 100644 (file)
@@ -379,8 +379,13 @@ static int fs_store_key(struct onak_dbctx *dbctx,
                }
 
                get_skshash(publickey, &hash);
-               hashid = (hash.hash[0] << 24) + (hash.hash[1] << 16) +
-                               (hash.hash[2] << 8) + hash.hash[3];
+               hashid = hash.hash[0];
+               hashid <<= 8;
+               hashid |= hash.hash[1];
+               hashid <<= 8;
+               hashid |= hash.hash[2];
+               hashid <<= 8;
+               hashid |= hash.hash[3];
                prove_path_to(hashid, "skshash", dbctx->config->location);
                skshashpath(wbuffer, sizeof(wbuffer), &hash,
                        dbctx->config->location);