Menu

False positive: Use of NULL or nullptr in sqlite3_open_v2

Erik S
2024-09-06
2024-09-06
  • Erik S

    Erik S - 2024-09-06

    The following code triggers a "Null pointer dereference" error:

    #include <sqlite3.h>
    #include <stddef.h>
    
    void f(const char* filename, int flags) {
        sqlite3* handle;
        sqlite3_open_v2(filename, &handle, flags, NULL);
        sqlite3_close_v2(handle);
    }
    

    cppcheck 2.15.0 outputs:

    $ cppcheck --library=sqlite3 ./test.c
    Checking test.c ...
    test.c:6:47: error: Null pointer dereference [nullPointer]
        sqlite3_open_v2(filename, &handle, flags, NULL);
    

    Looking at the SQLite documentation, using NULL (or nullptr in C++) is allowed and has a special meaning:

    If the fourth parameter is a NULL pointer then the default sqlite3_vfs object is used.

    This probably originates from commit 76f1aac which first appeared in v2.15.0.

     
  • CHR

    CHR - 2024-09-06

    Have you considered opening a PR at https://github.com/danmar/cppcheck?

     
  • CHR

    CHR - 2024-09-06
     

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.