I suggest you ...

Resolve the "correlated variables" problem in value tracking

In some code constructs, value tracking can become confused by mutually-exclusive code paths. This is also known as the "correlated variables" problem, and can cause erroneous Warning 661 (pointer access out of bounds) alerts.

I'd like to see PC-Lint be given the ability to determine mutually-exclusive code paths and remove these spurious warnings.

The following code sample demonstrates this:

#include <stdbool.h>
#include <stdint.h>
#include <string.h>

/*lint ++fan ++fas*/
typedef struct {
uint8_t One0[2];
uint8_t Two;
uint8_t One2[2];
} DATA_TYPE;
/*lint --fas --fan*/

typedef enum { CLASS_ONE, CLASS_TWO } DATA_CLASS;

bool SetOrClear(DATA_TYPE *as, const DATA_CLASS type, const size_t byte, const uint8_t mask, const bool state)
{
uint8_t *pset;
size_t ofs;

switch (type) {
case CLASS_ONE:
if (byte < sizeof(as->One0)) {
pset = as->One0;
ofs = byte;
} else {
ofs = byte - sizeof(as->One0);
if (ofs >= sizeof(as->One2)) {
return false;
}
pset = as->One2;
}
break;

case CLASS_TWO:
if (byte >= sizeof(as->Two)) {
return false;
}
pset = &as->Two;
ofs = byte;
break;

default:
return false;
}

if (state) {
pset[ofs] |= mask;
} else {
pset[ofs] &= ~mask;
}

return true;
}

6 votes
Vote
Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
You have left! (?) (thinking…)
Phil Pemberton shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

0 comments

Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
Submitting...

Feedback and Knowledge Base