jfs: avoid undefined behavior from left-shifting by 32 bits
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 5 lines · Nickolai Zeldovich
Shifting a 32-bit int by 32 bits is undefined behavior in C, and results in different behavior on different architectures (e.g., x86 and PowerPC).
diAlloc()infs/jfs/jfs_imap.ccomputes a mask using 0xffffffffu<<(32-bitno), which can left-shift by 32 bits. To avoid unexpected behavior, explicitly check for bitno==0 and use a 0 mask.
Thanks. Pushed togit://github.com/kleikamp/linux-shaggy.git jfs-next
Shaggy
Quoted 20 lines
Signed-off-by Nickolai Zeldovich <[email protected]>--- fs/jfs/jfs_imap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/jfs/jfs_imap.c +1
-1@@ -1493,7 +1493,7 @@ int diAlloc(struct inode *pip, bool dir, struct inode *ip)/* mask any prior bits for the starting words of the * summary map. */ - mask =ONES << (EXTSPERSUM - bitno); + mask = (bitno ==0 ) ?0 : (ONES << (EXTSPERSUM - bitno)); inosmap =le32_to_cpu (iagp->inosmap[sword]) | mask; extsmap =le32_to_cpu (iagp->extsmap[sword]) | mask;