libnml: Fixed memleak in configuration parsing#3701
Conversation
|
Instead of suppressing the cppcheck uninitialized warning, it may be appropriate just to initialize the double p1[9], p2[9], pl[9] = {};No comment on the mem-leak :-) |
I would like to keep the suppression as a reminder that the code is a bit tricky to read. Also, erroneously assigning a default value 0 or undefined is equally unfortunate, so the suppression is something like a quick statement that the devs are aware of the situation.
:) |
Tricky,... that is an understatement.
That is not necessarily a problem. The real problem is that cppcheck cannot perform the correct analysis. The code and compound condition makes The cppcheck message is a false positive. If you suppress the message, then you should at least precede it with a comment why the message needs to be suppressed. That would help to understand the "tricky" code a bit better ;-) |
| if(first || memcmp(p1, pl, sizeof(p1)) | ||
|
|
||
| // cppcheck-suppress uninitvar | ||
| if(first || memcmp(p1, pl, sizeof(p1)) // <- since first==1 when pl undefined |
There was a problem hiding this comment.
Here the explanation is given why the cppcheck error is suppressed.
There was a problem hiding this comment.
I'm sorry to be a nitpick here...
The comment is usually added before the suppress with a reference to the suppress.
// Suppress cppcheck false positive: 'first' == 1 when 'pl' is undefined and therefore not a problem
// cppcheck-suppress uninitvarf67604e to
63ab861
Compare
Also suppressing false positive report on use of undefined variable.
Also suppressing false positive report on use of undefined variable.