forked from danmar/cppcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlite3.c
More file actions
57 lines (48 loc) · 1.25 KB
/
sqlite3.c
File metadata and controls
57 lines (48 loc) · 1.25 KB
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
// Test library configuration for sqlite3.cfg
//
// Usage:
// $ cppcheck --check-library --library=sqlite3 --enable=style,information --inconclusive --error-exitcode=1 --disable=missingInclude --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 ignoredReturnValue(const char * buf)
{
// cppcheck-suppress leakReturnValNotUsed
sqlite3_malloc(10);
// cppcheck-suppress leakReturnValNotUsed
sqlite3_malloc64(5);
// cppcheck-suppress ignoredReturnValue
sqlite3_msize(buf);
}