Algorithm in Detecting Integer Overflows in C (on Unix)
Posted on 1998-02-23
How do I detect integer overflows in C, on Unix. The following is a sample code.
unsigned short int op1, op2, answer;
op1 = 65500;
op2 = 10;
answer = op1 * op2;
Is there a way that I can detect and prompt the user that the data being used to compute the multiplication in line #9 WILL CAUSE an integer overflow if computed. Is there any algorithm or method in detecting this ?
The algorithm I use must be able to handle unsigned long int as operand types instead of unsigned short int too !!!
Please help !! thanks