tags:

views:

45

answers:

3

Hi,

Klocwork reports an error of:-

"ABR – Buffer overflow, array index of 'oidsp' may be out of bounds. Array 'oidsp' of size 64 may use index value(s) -2..-1."

For this line:-

if (check_index_lower_legality (len,-1))
{
oidsp[len-1] = specProb;
}

When check_index_lower_legality is:-

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 ; 
}

However no bug when check_index_lower_legality is:- (which is by the way an incorrect answer , as for the offset values of -2 or -1 there will be a real error on runtime.

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;
}

Any ideas?

A: 

I don't think Klocwork can follow this type of logic through. You'd need to tell it that check_index_lower_legality behaves this way.

Vicky
+1  A: 

This is false bug. You need to add additional check for telling len is > 1 always.

So you can skip this bug by adding a totally unwanted if condition.

if (check_index_lower_legality (len,-1)) 
{
if(len > 1) 
oidsp[len-1] = specProb; 
} 

Or you can mark this bug as false alarm and run klockworks again. It will in most probable sense skip this in the next report.

Praveen S
A: 

Hi there, I could be missing something, but your function (check_index_lower_legality) doesn't modify the 'len' variable, nor is the return from the function used to access your array, so your snippet as provided would appear to correctly generate a runtime buffer underflow (for values of len < 0). Could you perhaps expand on the example if you believe the report to be truly incorrect?

Thanks, Gwyn.

Gwyn Fisher
Hi, my function doesn't modify a thing. It replies 0 if the sum of two parameters is lower than zero. Hence, there will not be a runtime buffer underflow, in the example above. The Klocwork doesn't seem to understand that the check done by the function should silent the bug.I have been having similar problems regarding char * Null termination. It seems the Klocwork is having problems with understanding that a function called a line or two before has solved the bug, and that there is no need for another check.
Moshe
You're right, my bad. Too quick of a reading on my part. As another poster says, mark it as FP (Not a Problem) and we'll propagate that status to all subsequent builds. On your other remark about NNTS, upgrading to 9.1 should remove the vast majority of these issues, as I commented on that thread.
Gwyn Fisher