From: Jonathan McDowell Date: Mon, 19 Aug 2019 06:28:16 +0000 (+0100) Subject: Clean up use of shifts beyond composite types X-Git-Tag: onak-0.6.0~28 X-Git-Url: https://the.earth.li/gitweb/?a=commitdiff_plain;h=da1f0ee80a15a9fb6a7d15e81f39ad9dc34db406;p=onak.git Clean up use of shifts beyond composite types 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. --- diff --git a/keydb_db4.c b/keydb_db4.c index df07769..d1947fe 100644 --- a/keydb_db4.c +++ b/keydb_db4.c @@ -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]); } diff --git a/keydb_fs.c b/keydb_fs.c index aabb616..f8d55dc 100644 --- a/keydb_fs.c +++ b/keydb_fs.c @@ -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);