How to check integer overflow in C?
Posted
by Ganker
on Stack Overflow
See other posts from Stack Overflow
or by Ganker
Published on 2010-04-13T22:31:58Z
Indexed on
2010/04/13
22:43 UTC
Read the original article
Hit count: 445
c
|integer-overflow
There's (1):
// assume x,y are non-negative
if(x > max - y) error;
And (2):
// assume x,y are non-negative
int sum = x + y;
if(sum < x || sum < y) error;
Whichs is preferred or is there a better way.
© Stack Overflow or respective owner