Menu

cppcheck will not recognize a function pointer

wy163
2026-07-30
2026-07-30
  • wy163

    wy163 - 2026-07-30

    Hi,

    Below code will be checked as null pointer dereference. But with the function call replaced with a function pointer, no error message will be reported. Seems cppcheck will not recognize a function pointer as a function.

    char * func(){return 0;}
    int main() {
    char * (*f_p)();
    f_p = func;
    char * p = func();
    *p = 'a';
    return 0;
    }
    

    Nothing reported.

    char * func(){return 0;}
    int main() {
    char * (*f_p)();
    f_p = func;
    char * p = f_p();
    *p = 'a';
    return 0;
    }
    
     
  • CHR

    CHR - 2026-07-30

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/14950

     

Log in to post a comment.