2019-03-13 13:57:40 +01:00
|
|
|
|
|
|
|
// Test library configuration for sqlite3.cfg
|
|
|
|
//
|
|
|
|
// Usage:
|
2023-03-09 20:04:20 +01:00
|
|
|
// $ cppcheck --check-library --library=sqlite3 --enable=style,information --inconclusive --error-exitcode=1 --disable=missingInclude --inline-suppr test/cfg/sqlite3.c
|
2019-03-13 13:57:40 +01:00
|
|
|
// =>
|
|
|
|
// 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) {
|
|
|
|
fprintf(stderr, "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);
|
2023-11-16 15:23:40 +01:00
|
|
|
// cppcheck-suppress resourceLeak
|
2019-03-13 13:57:40 +01:00
|
|
|
}
|
|
|
|
|
2023-08-05 18:48:43 +02:00
|
|
|
void ignoredReturnValue(const char * buf)
|
2019-03-13 13:57:40 +01:00
|
|
|
{
|
|
|
|
// cppcheck-suppress leakReturnValNotUsed
|
|
|
|
sqlite3_malloc(10);
|
|
|
|
// cppcheck-suppress leakReturnValNotUsed
|
|
|
|
sqlite3_malloc64(5);
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
sqlite3_msize(buf);
|
|
|
|
}
|