views:

24

answers:

1

Hi, I've been using PC-lint9 to find out different errors recently and it really blow my mind, but it seems PC-lint9 can't trace dangling pointer, here is snapshot of the code I exam with.

int* pkInt = new int;
int* pkDangInt = pkInt;
delete pkInt;
( *pkDangInt ) = 1;

there is no error detected by PC-Lint. I think there may be something wrong with the configuration( I didn't suppresss any error and set the warning level to 3 ) since the advertisement says: "Detection of dangling and uninitialised pointers". anyone knows how to solve this?

A: 

Probably the advertisement should be read as "Detection of some dangling...". The old dilemma between false positives and false negatives...

Now, I expect you think that is PC-lint is going to detect any dangling pointer at all, it should detect one your example, which is indeed rather simple. But perhaps the more structural one below is easier and indeed the only kind detected. Could you try it?

{
  int x;
  int* pkDangInt = &x;
}
( *pkDangInt ) = 1;
Pascal Cuoq
thanks Cuoq. Now I can try another way instead of trying to figure out how to make it work.
eddielu