Menu

[False positive] Portability: Returning an integer in a function with pointer return type

2020-07-06
2020-07-08
  • Toni Neubert

    Toni Neubert - 2020-07-06

    The following code creates a false-positive:

    int* f()
    {
      auto* i = static_cast<int*>(malloc(1));
      return i;
    }
    

    [test.cpp:4]: (portability) Returning an integer (int/long/etc) in a function with pointer return type is not portable across different platforms and compilers.

    The problem is, CppCheck tracks only the type of auto but not the complete type auto *

     

    Last edit: Toni Neubert 2020-07-06
  • Daniel Marjamäki

    I fail to reproduce with the latest cppcheck.

    The problem is, CppCheck tracks only the type of auto but not the complete type auto *

    Well it says that i has type signed int * as far as I see. Not sure maybe you have an old Cppcheck version that did not track this properly.

     
  • Toni Neubert

    Toni Neubert - 2020-07-08

    Ah, I see, thank you.

    We are using CppCheck 1.9 at the moment. I double checked the issue with the online demo (http://cppcheck.sourceforge.net/demo/) but this seems to use also an older version.

     

    Last edit: Toni Neubert 2020-07-08

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.