我需要确定特定代码行中变量的可能值范围。在一个复杂的项目中,这可能非常乏味且容易出错。这就是为什么我寻求一种可能性来自动化这项任务。想象一下以下简单的代码片段:
#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
}
有没有人知道以完整方式完成此任务的工具或任何其他方式?此外,我想根据一组给定的值范围检查结果值范围,理想情况下只得到不兼容的结果。