Library: Add initial configuration with tests for SQLite3 library. (#1737)
This commit is contained in:
parent
fd2a0f22a7
commit
1230357146
|
@ -0,0 +1,126 @@
|
|||
<?xml version="1.0"?>
|
||||
<def format="2">
|
||||
<!-- SQLite Library Configuration -->
|
||||
<!-- C API Reference: https://www.sqlite.org/capi3ref.html -->
|
||||
<!-- ########## SQLite Types ########## -->
|
||||
<!-- https://www.sqlite.org/capi3ref.html#sqlite3_int64 -->
|
||||
<podtype name="sqlite3_int64" sign="s" size="8"/>
|
||||
<podtype name="sqlite_int64" sign="s" size="8"/>
|
||||
<podtype name="sqlite3_uint64" sign="u" size="8"/>
|
||||
<podtype name="sqlite_uint64" sign="u" size="8"/>
|
||||
<!-- ########## SQLite values / defines ########## -->
|
||||
<define name="SQLITE_OK" value="0"/>
|
||||
<!-- ########## SQLite Memory Allocation / Deallocation ########## -->
|
||||
<!-- https://www.sqlite.org/capi3ref.html#sqlite3_free -->
|
||||
<memory>
|
||||
<alloc init="false">sqlite3_malloc</alloc>
|
||||
<alloc init="false">sqlite3_malloc64</alloc>
|
||||
<dealloc>sqlite3_free</dealloc>
|
||||
</memory>
|
||||
<!-- https://www.sqlite.org/capi3ref.html#sqlite3_str_new -->
|
||||
<memory>
|
||||
<alloc init="true">sqlite3_str_new</alloc>
|
||||
<dealloc>sqlite3_str_finish</dealloc>
|
||||
</memory>
|
||||
<!-- https://www.sqlite.org/capi3ref.html#sqlite3_str_finish -->
|
||||
<memory>
|
||||
<alloc init="true">sqlite3_str_finish</alloc>
|
||||
<dealloc>sqlite3_free</dealloc>
|
||||
</memory>
|
||||
<!-- ########## SQLite Resource Allocation / Deallocation ########## -->
|
||||
<!-- https://www.sqlite.org/capi3ref.html#sqlite3 -->
|
||||
<resource>
|
||||
<alloc arg="2">sqlite3_open</alloc>
|
||||
<alloc arg="2">sqlite3_open16</alloc>
|
||||
<alloc arg="2">sqlite3_open_v2</alloc>
|
||||
<dealloc>sqlite3_close</dealloc>
|
||||
<dealloc>sqlite3_close_v2</dealloc>
|
||||
</resource>
|
||||
<!-- ########## SQLite Functions ########## -->
|
||||
<!-- https://www.sqlite.org/capi3ref.html#sqlite3_close -->
|
||||
<!-- int sqlite3_close(sqlite3*); -->
|
||||
<!-- int sqlite3_close_v2(sqlite3*); -->
|
||||
<function name="sqlite3_close,sqlite3_close_v2">
|
||||
<noreturn>false</noreturn>
|
||||
<returnValue type="int"/>
|
||||
<arg nr="1">
|
||||
<not-uninit/>
|
||||
<not-bool/>
|
||||
</arg>
|
||||
</function>
|
||||
<!-- https://www.sqlite.org/capi3ref.html#sqlite3_errcode -->
|
||||
<!-- const char *sqlite3_errmsg(sqlite3*); -->
|
||||
<!-- const void *sqlite3_errmsg16(sqlite3*); -->
|
||||
<function name="sqlite3_errmsg,sqlite3_errmsg16">
|
||||
<noreturn>false</noreturn>
|
||||
<returnValue type="const char *"/>
|
||||
<arg nr="1">
|
||||
<not-uninit/>
|
||||
<not-bool/>
|
||||
</arg>
|
||||
</function>
|
||||
<!-- https://www.sqlite.org/capi3ref.html#sqlite3_finalize -->
|
||||
<!-- int sqlite3_finalize(sqlite3_stmt *pStmt); -->
|
||||
<function name="sqlite3_finalize">
|
||||
<noreturn>false</noreturn>
|
||||
<returnValue type="int"/>
|
||||
<arg nr="1">
|
||||
<not-bool/>
|
||||
</arg>
|
||||
</function>
|
||||
<!-- https://www.sqlite.org/capi3ref.html#sqlite3_free -->
|
||||
<!-- void sqlite3_free(void*); -->
|
||||
<function name="sqlite3_free">
|
||||
<noreturn>false</noreturn>
|
||||
<returnValue type="void"/>
|
||||
<arg nr="1">
|
||||
<not-bool/>
|
||||
</arg>
|
||||
</function>
|
||||
<!-- https://www.sqlite.org/capi3ref.html#sqlite3_free -->
|
||||
<!-- void *sqlite3_malloc(int); -->
|
||||
<function name="sqlite3_malloc">
|
||||
<noreturn>false</noreturn>
|
||||
<returnValue type="void *"/>
|
||||
<arg nr="1" direction="in">
|
||||
<not-uninit/>
|
||||
<not-bool/>
|
||||
<valid>1:</valid>
|
||||
</arg>
|
||||
</function>
|
||||
<!-- void *sqlite3_malloc64(sqlite3_uint64); -->
|
||||
<function name="sqlite3_malloc64">
|
||||
<noreturn>false</noreturn>
|
||||
<returnValue type="void *"/>
|
||||
<arg nr="1" direction="in">
|
||||
<not-uninit/>
|
||||
<not-bool/>
|
||||
<valid>1:</valid>
|
||||
</arg>
|
||||
</function>
|
||||
<!-- sqlite3_uint64 sqlite3_msize(void*); -->
|
||||
<function name="sqlite3_msize">
|
||||
<noreturn>false</noreturn>
|
||||
<returnValue type="sqlite3_uint64"/>
|
||||
<use-retval/>
|
||||
<arg nr="1" direction="in">
|
||||
<not-bool/>
|
||||
</arg>
|
||||
</function>
|
||||
<!-- https://www.sqlite.org/capi3ref.html#sqlite3_open -->
|
||||
<!-- int sqlite3_open(const char *filename, /* Database filename (UTF-8) */
|
||||
sqlite3 **ppDb /* OUT: SQLite db handle */); -->
|
||||
<function name="sqlite3_open">
|
||||
<noreturn>false</noreturn>
|
||||
<returnValue type="int"/>
|
||||
<arg nr="1" direction="in">
|
||||
<not-null/>
|
||||
<not-uninit/>
|
||||
<strz/>
|
||||
</arg>
|
||||
<arg nr="2" direction="out">
|
||||
<not-null/>
|
||||
<not-bool/>
|
||||
</arg>
|
||||
</function>
|
||||
</def>
|
|
@ -151,6 +151,33 @@ else
|
|||
fi
|
||||
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=boost ${DIR}boost.cpp
|
||||
|
||||
# sqlite3.c
|
||||
set +e
|
||||
pkg-config --version
|
||||
PKGCONFIG_RETURNCODE=$?
|
||||
set -e
|
||||
if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then
|
||||
echo "pkg-config needed to retrieve SQLite3 configuration is not available, skipping syntax check."
|
||||
else
|
||||
set +e
|
||||
SQLITE3CONFIG=$(pkg-config --cflags sqlite3)
|
||||
SQLITE3CONFIG_RETURNCODE=$?
|
||||
set -e
|
||||
if [ $SQLITE3CONFIG_RETURNCODE -eq 0 ]; then
|
||||
set +e
|
||||
echo -e "#include <sqlite3.h>" | ${CC} ${CC_OPT} ${SQLITE3CONFIG} -x c -
|
||||
SQLITE3CHECK_RETURNCODE=$?
|
||||
set -e
|
||||
if [ $SQLITE3CHECK_RETURNCODE -ne 0 ]; then
|
||||
echo "SQLite3 not completely present or not working, skipping syntax check with ${CC}."
|
||||
else
|
||||
echo "SQLite3 found and working, checking syntax with ${CC} now."
|
||||
${CC} ${CC_OPT} ${SQLITE3CONFIG} ${DIR}sqlite3.c
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=sqlite3 ${DIR}sqlite3.c
|
||||
|
||||
# Check the syntax of the defines in the configuration files
|
||||
set +e
|
||||
xmlstarlet --version
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
|
||||
// Test library configuration for sqlite3.cfg
|
||||
//
|
||||
// Usage:
|
||||
// $ cppcheck --check-library --library=sqlite3 --enable=information --error-exitcode=1 --inline-suppr --suppress=missingIncludeSystem 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) {
|
||||
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);
|
||||
// TODO: cppcheck-suppress resourceLeak
|
||||
}
|
||||
|
||||
void ignoredReturnValue(char * buf)
|
||||
{
|
||||
// cppcheck-suppress leakReturnValNotUsed
|
||||
sqlite3_malloc(10);
|
||||
// cppcheck-suppress leakReturnValNotUsed
|
||||
sqlite3_malloc64(5);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
sqlite3_msize(buf);
|
||||
}
|
|
@ -245,6 +245,7 @@ def scanPackage(workPath, cppcheckPath, jobs, fast):
|
|||
'python': ['<Python.h>'],
|
||||
'qt': ['<QApplication>', '<QString>', '<QWidget>', '<QtWidgets>', '<QtGui'],
|
||||
'sdl': ['<SDL.h>'],
|
||||
#'sqlite3': ['<sqlite3.h>'], <- Enable after release of 1.88
|
||||
'tinyxml2': ['<tinyxml2', '"tinyxml2'],
|
||||
'wxwidgets': ['<wx/', '"wx/'],
|
||||
'zlib': ['<zlib.h>'],
|
||||
|
|
Loading…
Reference in New Issue