I need to determine the possible value range of a variable in a specific line of code. In a complex project this can be very tedious and error prone. Thats why i seek a possibility to automate this task. Imagine the following easy code snippet:
#define checkBoundary(value) if((value)<100 || (value)> 1000) return;
bool checkmaximumForMode0(value)
{
return (value>100);
}
void main(void)
{
int mode = rand()%4;
// x shall be any valid value for an int, just for the sake of completion i use rand here.
int x = rand();
if (x < 0)
return;
switch(mode)
{
case 0:
if(checkmaximumForMode0(x)) return;
case 1:
checkBoundary(x);
default:
if (x<10000)
goto exit;
}
// Now i want to know, which value range of x will i have under what circumstances
int isChecked = x;
// For this easy example:
// Codepath 1(mode = 0): x >= 0 && x <= 100
// Codepath 2(mode = 1): x >= 100 && x <= 1000
// Codepath 3(mode = 2..3): x >= 10000 && x <= maxint
exit:
print( "Exiting");
return
}
Does anybody know of a tool or any other way for achieving this task in a complete manner? Furthermore i want to check the resulting value ranges against a given set of value ranges and ideally get only incompatibilities as a result.