Fix cppcheck reports:#133
Conversation
[tests/libtest/lib1900.c:182]: (style) Array index 'handlenum' is used before limits check. [docs/examples/sepheaders.c:65]: (error) Resource leak: headerfile
|
Hi Julien, Many thanks. I've pushed your modification to sepheaders.c but have a question for you about the modification to lib1900.c: Is the check for 'handlenum < num_handles' needed in that second if statement, in order to pass cppcheck, given that the same check happens a few lines up and the values of 'handlenum' and 'num_handles' are not modified in between the two if statements? Unless I've missed something I don't think it is needed from a logic point of view. Kind Regards Steve |
|
You're right, I think cppcheck isn't smart enough to detect that the check already exists some line above. |
|
Hi again, I think the check being in the second part of the second if statement may be confusing cppcheck as well :( Are you able to test this theory and produce a patch if it is successful - as I don't run cppcheck personally? Many thanks Steve |
|
Ok if I do this:
|
|
Cheers Julien, I'll prepare a patch on your behalf and push it. Fyi: Daniel has started to use Coverity to scan the source code over recent months and I've just been looking at the cppcheck website, whilst compiling various patches, so I will try cppcheck myself over the next few days. Thanks again Steve |
|
Great! |
lib1900.c:182: (style) Array index 'handlenum' is used before limits
check
Bug: #133
|
Pushed as commit ee0941a. |
[tests/libtest/lib1900.c:182]: (style) Array index 'handlenum' is used before limits check.
[docs/examples/sepheaders.c:65]: (error) Resource leak: headerfile