File: sqlite3.c

package info (click to toggle)
cppcheck 2.19.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 26,412 kB
  • sloc: cpp: 272,462; python: 22,408; ansic: 8,088; sh: 1,059; makefile: 1,041; xml: 987; cs: 291
file content (71 lines) | stat: -rw-r--r-- 1,741 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

// Test library configuration for sqlite3.cfg
//
// Usage:
// $ cppcheck --check-library --library=sqlite3 --enable=style,information --inconclusive --error-exitcode=1 --inline-suppr test/cfg/sqlite3.c
// =>
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
//

#include <sqlite3.h>
#include <stdio.h>

void validCode()
{
    sqlite3 * db;

    int rc = sqlite3_open("/db", &db);
    if (rc != SQLITE_OK) {
        printf("Error opening sqlite3 db: %s\n", sqlite3_errmsg(db));
        sqlite3_close(db);
    } else {
        sqlite3_close(db);
    }

    {
        char * buf = sqlite3_malloc(10);
        printf("size: %ull\n", sqlite3_msize(buf));
        sqlite3_free(buf);
    }
}

void memleak_sqlite3_malloc()
{
    char * buf = sqlite3_malloc(10);
    if (buf) {
        buf[0] = 0;
    }
    // cppcheck-suppress memleak
}

void resourceLeak_sqlite3_open()
{
    sqlite3 * db;

    sqlite3_open("/db", &db);
    // cppcheck-suppress resourceLeak
}

void resourceLeak_sqlite3_open_v2(const char* Filename, int Flags, int Timeout, const char* Vfs) { // #12951, don't crash
    sqlite3* handle;
    const int ret = sqlite3_open_v2(Filename, &handle, Flags, Vfs);
    if (SQLITE_OK != ret) {}
    if (Timeout > 0) {}
    // cppcheck-suppress resourceLeak
}

void nullPointer_sqlite3_open_v2(const char* filename, int flags) { // #13078
    sqlite3* handle;
    sqlite3_open_v2(filename, &handle, flags, NULL);
    sqlite3_close_v2(handle);
}

void ignoredReturnValue(const char * buf)
{
    // cppcheck-suppress leakReturnValNotUsed
    sqlite3_malloc(10);
    // cppcheck-suppress leakReturnValNotUsed
    sqlite3_malloc64(5);
    // cppcheck-suppress ignoredReturnValue
    sqlite3_msize(buf);
}