Signed overflow optimization hazards in the kernel
Signed overflow optimization hazards in the kernel
Posted Aug 17, 2012 19:09 UTC (Fri) by iabervon (subscriber, #722)In reply to: Signed overflow optimization hazards in the kernel by cmccabe
Parent article: Signed overflow optimization hazards in the kernel
int find(char *s, char c, int lim)
{
for (int i = 0; i != lim && s[i]; i++)
if (s[i] == c)
return i;
return -1;
}
int main()
{
find("foo", 'o', 1);
find("foo", 'o', -1);
}
If the compiler inlines the second call, it can drop the "i != lim" test by assuming that overflow is impossible.
