Why Warning 661

Post a reply


This question is a means of preventing automated form submissions by spambots.

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is OFF
Smilies are OFF

Topic review
   

Expand view Topic review: Why Warning 661

Re: Why Warning 661

by mmetivier » Thu Jan 09, 2020 2:50 pm

Likely because Lint believes that your "count" could be anything in range of a signed int. While your check ensures that it doesn't use anything that will cause an access off the "left" of the buf, that still leaves Lint with the belief that the range could be anything from [1:2147483647]. So, if count were, in fact, 2147483647, you'd be 2147479647 elements off the end of the array, hence the warning.

You could resolve this by letting Lint know that you are aware of this by either expanding your conditional, so that " && count < 4000", or using assert to verify the same thing.

Why Warning 661

by SeeCwriter » Mon Jan 06, 2020 6:15 pm

With the following test class

Code: Select all

class myclass 
{
public: 
  int count;
  buf[4000];
  myclass(): count(0) {buf[0]=0;}
  void RemoveLast();
}
 
myclass::RemoveLast()
{
  if ( count > 1 ) buf[count - 1] = 0; <-- Warning 661
}
I don't understand why I'm getting waring 661:

Code: Select all

packet.cpp  369  warning 661: potential out of bounds pointer access: excess of 
    0:2147479647 bytes
  if ( count > 1 ) buf[count - 1] = 0;
                   ^    ~~~~~~~~

Top