Re: Unsigned widening casts of binary "not" operations..

From: Theodore Ts'o
Date: Tue Apr 23 2013 - 09:00:59 EST


On Mon, Apr 22, 2013 at 05:15:19PM -0700, Linus Torvalds wrote:
> Here's a ext4 code snippet that looks like an actual bug (but seems to only
> hit read-ahead):
>
> ext4_fsblk_t b, block;
>
> b = block & ~(EXT4_SB(sb)->s_inode_readahead_blks-1);
>
> where "b" actually ends up having the upper bits cleared, because the
> s_inode_readahead_blks thing is an unsigned int, so you're masking off not
> just the low bits, but the high bits too. Ted? Of course, it's just
> read-ahead, so it probably doesn't matter, but.

Yep, it's a bug alright. Thanks for catching it!

- Ted