Menu

Parsing ternary expression

2023-07-07
2023-07-07
  • Martin Poupě

    Martin Poupě - 2023-07-07

    Hi,
    I found (probably) false positive, when cpp_check thinks it can predict variable value to zero, so the for loop can be removed at all. The simplest program is:

    #include <stdint.h>
    #include <stddef.h>
    void dump(uint8_t c);
    
    void dumpfew(const uint8_t *p, size_t size)
    {
        size_t i,dsize = (size > 32) ? 32 : size;
        for(i = 0; i < dsize;i++)
        {
            dump(p[i]);
        }
    }
    

    Your online demo says : Cppcheck 2.10 [test.cpp:8]: (style) Condition 'iDone!
    Cppcheck 2.11 on my project says:
    style: Condition 'i<dsize' is="" always="" false="" <span="">[knownConditionTrueFalse] note: Assignment 'dsize = (size>32)?32:size', assigned value is less than 1</dsize'>

    I think nothing can be predicted, because the function is not static, so it can be called from anywhere with any parameters. Or did I miss something?

    Best Regards Martin

     
  • CHR

    CHR - 2023-07-07

    I think this is related to https://trac.cppcheck.net/ticket/11437

     
  • Martin Poupě

    Martin Poupě - 2023-07-07

    @CHR : Yes, it looks like the same problem.

     

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.