Menu

missingReturn check failed

2023-05-17
2023-05-18
  • Enrico Benso

    Enrico Benso - 2023-05-17

    Hello,

    it seems that cppcheck 2.10.3 is failing in giving the missingReturn error in this simple function:

    uint32_t test(void)
    {
    printk("Debug \n");
    //return 10;
    }

    where printk is implemented in Zephyr OS.

     
  • CHR

    CHR - 2023-05-17

    printk() is unknown to cppcheck, so it is assumed to be a noreturn function. This could be solved by creating a library file.

     
  • Enrico Benso

    Enrico Benso - 2023-05-17

    Could you please explain how I should manage this?
    In general we use a lot of external libraries in our code and we don't want to analyze them.
    How to avoid to get these kind of false negatives?

    Thanks

     
  • CHR

    CHR - 2023-05-17

    There are a couple of library files in cppcheck/cfg/ already, but none of them contain printk. You could create a linux.cfg containing

    <?xml version="1.0"?>
    <def format="2">
      <function name="printk">
        <returnValue type="int"/>
        <noreturn>false</noreturn>
        <leak-ignore/>
        <formatstr/>
        <arg nr="1" direction="in">
          <formatstr/>
          <not-uninit/>
          <strz/>
        </arg>
      </function>
    </def>
    

    then call cppcheck --library=linux.cfg

     
  • Enrico Benso

    Enrico Benso - 2023-05-18

    Ok, understood. Anyway I think this is feasible only if the project uses just few functions from external libray, in my case I have a lot of callings to Zephyr functions, it'll be very hard to create such .cfg file.

    Is it possibile to configure cppcheck to treat unknown functions as returning functions?

     

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.