With CPPCheck version 2.6:
In the output of the --errorlist option, objectIndex is reported with severity "error" but when actually generated during a check run it is generated with severity "warning". I think the latter is more appropriate.
cppcheck--errorlist|grepobjectInd<errorid="objectIndex"severity="error"msg="The address of local variable '' is accessed at non-zero index."verbose="The address of local variable '' is accessed at non-zero index."cwe="758"/>
when in the results of a code check:
<errorcwe="758"file0="..."id="objectIndex"msg="The address of local variable 'aRef' might be accessed at non-zero index."severity="warning"verbose="The address of local variable 'aRef' might be accessed at non-zero index."><locationcolumn="31"file="..."info=""line="103"/><locationcolumn="25"file="..."info="Address of variable taken here."line="103"/></error>
Can the errorlist output be corrected please?
Last edit: david ingamells 2022-02-10
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
<?xml version="1.0" encoding="UTF-8"?><resultsversion="2"><cppcheckversion="2.7"/><errors>
Checking test.cpp ...
<errorid="objectIndex"severity="error"msg="The address of local variable 'i' is accessed at non-zero index."verbose="The address of local variable 'i' is accessed at non-zero index."cwe="758"file0="test.cpp"><locationfile="test.cpp"line="4"column="10"/><locationfile="test.cpp"line="3"column="9"info="Address of variable taken here."/></error></errors></results>
Both match the --errorlist output.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In your (david) case the message says that the object "might" be accessed at non-zero index.
In "chr" case the message says that the object "is" accessed at non-zero index.
That wording tells me that the severity should be a bit different. A "error" should only be reported when there "is" an actual bug every time the line of code that we warn about is executed.
Last edit: Daniel Marjamäki 2022-02-13
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For information here is the Cppcheck source code that reports these error messages:
voidCheckBufferOverrun::objectIndexError(constToken*tok,constValueFlow::Value*v,boolknown){ErrorPatherrorPath;std::stringname;if(v){name=v->tokvalue->variable()->name();errorPath=v->errorPath;}errorPath.emplace_back(tok,"");std::stringverb=known?"is":"might be";reportError(errorPath,known?Severity::error:Severity::warning,"objectIndex","The address of local variable '"+name+"' "+verb+" accessed at non-zero index.",CWE758,Certainty::normal);}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
--xml Write results in xml format to error stream (stderr).
Regarding the severity, it is a surprise to me that an error Id can get 2 different severities, contrary to what the --errorlist says/implies. I have just implemented a filter that uses the--errorlist output's severities to determine how to treat each error id.
Oh well, back to the drawing board.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
A request:
Would it be possible to extend the output of --errorlist to list all the possible severities for each error id? That would make my work much easier. As it is now, apart from scouring through the source code of cppcheck, I don't see how I can know which severities are possible for each error id, or which error texts (e..g "might be" vs "is") can be produced.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
that would also be difficult for us I am afraid. but I would assume that most "error" messages can also be reported as "warning". but other severities "style", "performance", "portability", "information" should not be used as far as I know.
As far as I know a "warning", "style", "performance", "portability", "information" message will only be reported with that severity. I don't know off-the-top-of-my-head why a "warning" would sometimes be reported as "style" for instance.
Last edit: Daniel Marjamäki 2022-02-14
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
With CPPCheck version 2.6:
In the output of the --errorlist option, objectIndex is reported with severity "error" but when actually generated during a check run it is generated with severity "warning". I think the latter is more appropriate.
when in the results of a code check:
Can the errorlist output be corrected please?
Last edit: david ingamells 2022-02-10
How did you obtain the xml result?
With just
cppcheck
I get (using head):Adding
--xml
:Both match the
--errorlist
output.The severity often depends on the certainty.
In your (david) case the message says that the object "might" be accessed at non-zero index.
In "chr" case the message says that the object "is" accessed at non-zero index.
That wording tells me that the severity should be a bit different. A "error" should only be reported when there "is" an actual bug every time the line of code that we warn about is executed.
Last edit: Daniel Marjamäki 2022-02-13
For information here is the Cppcheck source code that reports these error messages:
Regarding how I used:
Regarding the severity, it is a surprise to me that an error Id can get 2 different severities, contrary to what the
--errorlist
says/implies. I have just implemented a filter that uses the--errorlist
output's severities to determine how to treat each error id.Oh well, back to the drawing board.
A request:
Would it be possible to extend the output of
--errorlist
to list all the possible severities for each error id? That would make my work much easier. As it is now, apart from scouring through the source code of cppcheck, I don't see how I can know which severities are possible for each error id, or which error texts (e..g "might be" vs "is") can be produced.that would also be difficult for us I am afraid. but I would assume that most "error" messages can also be reported as "warning". but other severities "style", "performance", "portability", "information" should not be used as far as I know.
As far as I know a "warning", "style", "performance", "portability", "information" message will only be reported with that severity. I don't know off-the-top-of-my-head why a "warning" would sometimes be reported as "style" for instance.
Last edit: Daniel Marjamäki 2022-02-14