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.
{
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]);
}
}
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);