Skip to content

Commit

Permalink
jfs: avoid undefined behavior from left-shifting by 32 bits
Browse files Browse the repository at this point in the history
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() in fs/jfs/jfs_imap.c computes 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.

Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu>
Signed-off-by: Dave Kleikamp <dave.kleikamp@oracle.com>
  • Loading branch information
Nickolai Zeldovich authored and Dave Kleikamp committed Jan 7, 2013
1 parent 5f243b9 commit 9d48017
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion fs/jfs/jfs_imap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 9d48017

Please sign in to comment.