Klocwork 报告错误:-
"ABR – Buffer overflow, array index of 'oidsp' may be out of bounds. Array 'oidsp' of size 64 may use index value(s) -2..-1."
对于这一行:-
if (check_index_lower_legality (len,-1))
{
oidsp[len-1] = specProb;
}
当 check_index_lower_legality 为:-
bool check_index_lower_legality (int index, int offset)
/**
* This function checks that the index with the offset isn't
* below zero.
* If it is - returns 0 ;
* If isn't - returns 1 ;
**/
{
if ( (index + offset )<0) {
return 0;
}
return 1 ;
}
但是,当 check_index_lower_legality
为:-
(顺便说一句,这是一个不正确的答案,对于 -2 或 -1 的偏移值,运行时会出现真正的错误。
bool check_index_lower_legality (int index, int offset)
/**
* This function checks that the index with the offset isn't
* below zero.
* If it is - returns 0 ;
* If isn't - returns 1 ;
**/
{
if (index <=0) {
return 0;
}
return 1;
}
有什么想法吗?
最佳答案
这是错误的错误。您需要添加额外的检查来告诉 len 始终 > 1。
因此,您可以通过添加完全不需要的 if 条件来跳过此错误。
if (check_index_lower_legality (len,-1))
{
if(len > 1)
oidsp[len-1] = specProb;
}
或者您可以将此错误标记为误报并再次运行 klockworks。很可能在下一份报告中跳过这一点。
关于c - ABR - Klocwork 错误警报和错误处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3253875/