Menu

" Found suspicious operator',' " false call ?

gluttony38
2019-12-09
2021-11-27
  • gluttony38

    gluttony38 - 2019-12-09

    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):

    #include <opencv2/core/mat.hpp>
    
    void Test()
    {
        cv::Mat M = (cv::Mat_<double>(3,3) << 1, 0, 0, 0, 1, 0, 0, 0, 1);
    }
    

    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
  • versat

    versat - 2019-12-09

    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.

     
  • gluttony38

    gluttony38 - 2019-12-10

    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.

     
  • Philipp Hasper

    Philipp Hasper - 2020-02-14

    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?

     
  • Daniel Marjamäki

    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.

     
  • Philipp Hasper

    Philipp Hasper - 2020-02-18

    @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

     
  • Philipp Hasper

    Philipp Hasper - 2020-02-21

    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

    1. I removed the error-exitcode parameter from the call so the command always is successful
    2. 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
    3. Then mv CPPCheckReport_Sanitized.xml CPPCheckReport.xml
    4. To mimic the exitcode behavior, I count the remaining errors:
    if [ $(xmlstarlet sel -t -v "count(//error)" CPPCheckReport.xml) -ne "0" ]; then
      exit 1
    fi
    
     
  • Daniel Marjamäki

    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.

     
  • syun

    syun - 2021-09-27

    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?

     
  • Daniel Marjamäki

    Could you show an example code? For the original example shown I don't see that warning message.

     
  • syun

    syun - 2021-09-27
    #include <iostream>
    #include <Eigen/Dense>
    
    int main()
    {
            Eigen::Matrix3f m;
            m << 1, 2, 3,
                        4, 5, 6;
    }
    

    The example code above was taken from the site below.
    https://eigen.tuxfamily.org/dox/group__TutorialMatrixClass.html

     

    Last edit: syun 2021-09-27
    • syun

      syun - 2021-09-28

      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.

       
  • CHR

    CHR - 2021-09-28

    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.

     
    • Daniel Marjamäki

      Is this something that could be solved with a configuration file?

      Yes I think we should have some configuration. Not sure how to configure it.. wild idea:

      <operator-overload op="<<" type1="Eigen::Matrix3f" result="Eigen::Matrix3f::_"/>
      <operator-overload op="," type1="Eigen::Matrix3f::_" result="Eigen::Matrix3f::_"/>
      

      and then the tokenizer could replace:

      m << 1,2;
      

      with:

      m.operator<<(1).operator,(2);
      

      so this should not be used in general for all overloaded operators, just when there is non-standard behavior and we need to "bailout".

       
      • Daniel Marjamäki

        Here is a self-contained example:

        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.

         
  • syun

    syun - 2021-09-29

    Here is example code about Eigen::Matrix with comma initialization

    Eigen::MatrixXd kk;
    kk.resize(1,3);
    kk << 1, 2, 3;
    

    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
    • Daniel Marjamäki

      I feel that this is the same question you asked 2 days ago.

       
      • syun

        syun - 2021-09-29

        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
        • Daniel Marjamäki

          Yes. A fix in cppcheck will be needed.

           
          • Daniel Marjamäki

            I created this ticket: https://trac.cppcheck.net/ticket/10518 for the cppcheck fix.

             
            • syun

              syun - 2021-10-01

              Thank you for your answer.

               
  • Amin Yahyaabadi

    Amin Yahyaabadi - 2021-11-24

    Is there any update on the opened ticket? How can I use the suggested xml fix?

     
    • Daniel Marjamäki

      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.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.