Question: Hello, how would I go about detecting integer overflow for unsigned integers? My current implementation uses the atoi function and a comparison to UINT_MAX. I
Hello, how would I go about detecting integer overflow for unsigned integers? My current implementation uses the atoi function and a comparison to UINT_MAX. I know that this is incorrect but I am not sure how to remedy it. Thank you.
#include
#include
#include
int main(int argc, char **argv)
{
unsigned int i = 1;
unsigned int sum;
sum = atoi(argv[1]);
if (sum + 1 > UINT_MAX)
{
printf("Overflow detected. ");
}
else
{
printf("No overflow detected. ");
}
}
Thank you for any help.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
