Menu

False positive: return value of function pointer [AssignmentAddressToInteger]

anoy.
2020-06-30
2020-06-30
  • anoy.

    anoy. - 2020-06-30

    Some function pointers seem to confuse Cppcheck so that it thinks it was assigned directly to the integer.

    void f()
    {
        using tfDllFunc0 = int __stdcall(int * aCas, char * aStrIn, void * aPtr1, void * aPtr2, void * aPtr3, void *aPtr4, char * aStrOut);
        using tfDllFunc1 = int __stdcall(char * aStr);
        using tfDllFunc2 = int __stdcall(int aValue, char * aStr);
    
        tfDllFunc0 *fDllFunc0 = QLibrary::resolve("Test.dll", "_func0@0");
        tfDllFunc1 *fDllFunc1 = QLibrary::resolve("Test.dll", "_func1@0");
        tfDllFunc2 *fDllFunc2 = QLibrary::resolve("Test.dll", "_func2@0");
    
        char vStr[256] = {};
        int vInt = 0;
        int rc = fDllFunc0(&vInt, nullptr, nullptr, nullptr, nullptr, nullptr, vStr); // AssignmentAddressToInteger
        (void)rc;
        rc = fDllFunc1(vStr); // AssignmentAddressToInteger
        (void)rc;
        rc = fDllFunc2(5, vStr); // no warning
        (void)rc;
    }
    
     
  • Daniel Marjamäki

    Thanks! I can reproduce with cppcheck-2.0. With git head I get a segmentation fault.
    I created ticket https://trac.cppcheck.net/ticket/9792

     

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.