It looks like operator overloading or so is necessary to use such a comma-separated initializer. Not sure how this is implemented.
Creating a library configuration for OpenCV is on my TODO list. I have not used OpenCV, so I am not familiar with it, but I wanted to create an initial configuration that can be futher enhanced then.
While this library configuration could help with some issues, I am not sure if it can help in that case. Not everything can be configured in that file.
Maybe someone else has an idea how to fix this false positive.
BTW: The inserted code is malformed, you can prevent this by marking it as code. You can for example simply indent the code by 4 spaces, then it is shown correctly.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for you answer, for the malformed code I just changed it, but since new topics are opened through send of and e-mail I was not sure of the syntax, and by the way the text should have been all the same size, I don't know why de "#include ..." was so big.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
We have the same issue with OpenCV types and also with types derived from Eigen's EMatrix. @versat Is there a way to suppress this warning globally for a code base? ideally only for the , operator?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It would be easiest to update the suppressions (symbolName attribute could contain the operator).
But well that is not the perfect solution. How do we solve this properly. maybe it should be possible to define operator overloads in cfg files. It would be much better for Cppcheck analysis if we parsed this code properly.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@danielmarjamaki I think a more versatile suppression than just deactivating all constStatement (because this is the ID returned for these errors) is always a good thing to have. And if it is the easy solution, that's also a plus point.
I think even if the perfect solution is done, the updated suppressions will still come in handy for some future edge cases
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For everybody stumbling over the same problem, this is how I currently work around this:
Prerequisites: My cppcheck command initially had the parameter --error-exitcode=1 and --output-file=CPPCheckReport.xml
I removed the error-exitcode parameter from the call so the command always is successful
Using xmlstartlet (http://xmlstar.sourceforge.net/) I delete all the "supicous operator ,": xmlstarlet ed -d "//error[@msg=\"Found suspicious operator ','\"]" CPPCheckReport.xml > CPPCheckReport_Sanitized.xml
Then mv CPPCheckReport_Sanitized.xml CPPCheckReport.xml
To mimic the exitcode behavior, I count the remaining errors:
if [ $(xmlstarletsel-t-v"count(//error)"CPPCheckReport.xml)-ne"0" ]; thenexit1fi
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Is this something that could be solved with a configuration file? OpenCV's matrix classes support similar assignment, but there are no provisions for it in opencv2.cfg so far.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry you can not use the suggested xml fix yet because we have not implemented this handling yet. It was not intended as a workaround suggestion I believe but as a proper fix.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
Tu reproduce it, just use OpenCV cv::Mat example to create a 3x3
double-precision identity matrix (see
https://docs.opencv.org/4.1.2/d3/d63/classcv_1_1Mat.html):
Running cppckeck Test.cpp --force --platform=unix64 --enable=warning
--xml-version=2 --verbose --error-exitcode=0 --std=c++11 --language=c++
command gives a " Found suspicious operator',' " warning on "cv::Mat M
=..." line.
Could you please check on this ?
Thanks
Last edit: gluttony38 2019-12-10
It looks like operator overloading or so is necessary to use such a comma-separated initializer. Not sure how this is implemented.
Creating a library configuration for OpenCV is on my TODO list. I have not used OpenCV, so I am not familiar with it, but I wanted to create an initial configuration that can be futher enhanced then.
While this library configuration could help with some issues, I am not sure if it can help in that case. Not everything can be configured in that file.
Maybe someone else has an idea how to fix this false positive.
BTW: The inserted code is malformed, you can prevent this by marking it as code. You can for example simply indent the code by 4 spaces, then it is shown correctly.
Thanks for you answer, for the malformed code I just changed it, but since new topics are opened through send of and e-mail I was not sure of the syntax, and by the way the text should have been all the same size, I don't know why de "#include ..." was so big.
We have the same issue with OpenCV types and also with types derived from Eigen's EMatrix. @versat Is there a way to suppress this warning globally for a code base? ideally only for the
,
operator?It would be easiest to update the suppressions (symbolName attribute could contain the operator).
But well that is not the perfect solution. How do we solve this properly. maybe it should be possible to define operator overloads in cfg files. It would be much better for Cppcheck analysis if we parsed this code properly.
@danielmarjamaki I think a more versatile suppression than just deactivating all constStatement (because this is the ID returned for these errors) is always a good thing to have. And if it is the easy solution, that's also a plus point.
I think even if the perfect solution is done, the updated suppressions will still come in handy for some future edge cases
For everybody stumbling over the same problem, this is how I currently work around this:
Prerequisites: My cppcheck command initially had the parameter
--error-exitcode=1
and--output-file=CPPCheckReport.xml
xmlstarlet ed -d "//error[@msg=\"Found suspicious operator ','\"]" CPPCheckReport.xml > CPPCheckReport_Sanitized.xml
mv CPPCheckReport_Sanitized.xml CPPCheckReport.xml
I wonder if you could send us a github pull request that sets the symbolname?
I think all you need to do.. is to add a line that says: "$symbol:," in the reportError. you can see how $symbol is used in other error reports.
Hi
I recently started using Cppcheck, and I also had the same problem as above. But looking at the comments, I don't know how to solve the above problem.
Could you tell me?
Could you show an example code? For the original example shown I don't see that warning message.
The example code above was taken from the site below.
https://eigen.tuxfamily.org/dox/group__TutorialMatrixClass.html
Last edit: syun 2021-09-27
In my code, when initializing or assigning a value to the Eigen::Matrix using "<<", I get an error as below.
Found suspicious operator ','
Please, Tell me how to solve this.
Here is a self-contained example:
https://godbolt.org/z/oe639Ksr7
Is this something that could be solved with a configuration file? OpenCV's matrix classes support similar assignment, but there are no provisions for it in opencv2.cfg so far.
Yes I think we should have some configuration. Not sure how to configure it.. wild idea:
and then the tokenizer could replace:
with:
so this should not be used in general for all overloaded operators, just when there is non-standard behavior and we need to "bailout".
For that I would like that no configuration is needed. I am afraid we don't handle overloaded operators 100%.. but it's something to improve.
Here is example code about Eigen::Matrix with comma initialization
More technical details about comma initialization can be found in the references below.
Link : https://eigen.tuxfamily.org/dox/group__TutorialAdvancedInitialization.html
The Cppcheck reports " CWE: 398 Found suspicious operator ',' " at third line in above code.
I think, "<<" and "," are not overloaded operator, just Comma Initialization in Eigen::Matrix
Could anyone give me some advice about solving that issue?
or
If I'm misunderstanding something, can you please tell me which part it is?
Last edit: syun 2021-09-29
I feel that this is the same question you asked 2 days ago.
Do you mean the sentence you replied eighteen hours ago is the solution or good method to solve my problem?
Last edit: syun 2021-09-29
Yes. A fix in cppcheck will be needed.
I created this ticket: https://trac.cppcheck.net/ticket/10518 for the cppcheck fix.
Thank you for your answer.
Is there any update on the opened ticket? How can I use the suggested xml fix?
Sorry you can not use the suggested xml fix yet because we have not implemented this handling yet. It was not intended as a workaround suggestion I believe but as a proper fix.