On 11/26/2014 12:55 PM, Linus Torvalds wrote: > On Nov 26, 2014 6:00 AM, "Sasha Levin" <sasha.le...@oracle.com > <mailto:sasha.le...@oracle.com>> wrote: >> >> We've used to detect integer overflows by causing an overflow and testing the >> result. For example, to test for addition overflow we would: >> >> if (a + b < a) >> /* Overflow detected */ >> >> While it works, this is actually an undefined behaviour and we're not >> guaranteed to have integers overflowing this way. > > Bullshit. > > Integer overflow is completely well defined in unsigned types. > > Don't make up things like this.
Yes, I messed up and picked case where both types are unsigned in my example patch. Apologies. The kernel still has it's share of *signed* integer overflows. Example? fadvise64_64(): loff_t offset, len; [...] loff_t endbyte; [...] /* Careful about overflows. Len == 0 means "as much as possible" */ endbyte = offset + len; if (!len || endbyte < len) endbyte = -1; else endbyte--; /* inclusive */ In essence, it's checking (offset + len < len), all of which are signed. Thanks, Sasha -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/