Commit Graph

393 Commits

Author SHA1 Message Date
orbitcowboy aed5e17867 #9323, #9331: Moved configuration and tests to gnu and bsd. 2019-09-08 19:17:15 +02:00
orbitcowboy 12c851d9a8 posix.cfg: Fixed #9323, #9331 by adding timercmp() configuration. 2019-09-07 10:42:09 +02:00
Sebastian 4531b31a4a
Test for issue 9334: FP resourceLeak for dlopen/dlclose with library posix (#2151)
Add test to avoid further FP for valid code.
Tests for true positives are already present.
https://trac.cppcheck.net/ticket/9334
2019-09-06 16:37:51 +02:00
Sebastian 32dad3f44a
posix.cfg: Fix vsyslog() configuration (#2150)
Add tests to make sure no false positives are reported.
Found the issue via daca@home
2019-09-06 10:16:11 +02:00
Daniel Marjamäki 068b0ef648 Make Travis happy 2019-09-04 13:38:19 +02:00
Sebastian a501f65c8c
libcurl.cfg: Add library configuration for libcurl (#2120)
Add curl_easy_*() functions and deprecated functions with warnings.
Add tests and prepare donate-cpu.py
Reference: https://curl.haxx.se/libcurl/c/
2019-08-29 15:11:59 +02:00
Sebastian 8782a5f5e4
lua.cfg: Add Lua C API library configuration with tests (#2119) 2019-08-29 11:38:21 +02:00
orbitcowboy 1994cbbb9c std.cfg: Improved configuration for mbrlen() and extended test cases. 2019-08-27 08:18:19 +02:00
orbitcowboy c8b7b40cd7 wxwidgets.cfg: Improved support for wxString member functions. 2019-08-25 15:54:50 +02:00
Daniel Marjamäki 4bd9d76a4c Try to make Travis happy 2019-08-25 10:24:13 +02:00
Sebastian f25dcd5cda
python.cfg: Add Py_CLEAR(), and add initial test file (#2110) 2019-08-24 10:17:23 +02:00
Sebastian 7f50642090
wxwidgets.cfg: Add container configuration for wxString (#2109) 2019-08-23 19:10:49 +02:00
Sebastian 2c673bd380
qt.cfg: Add container configuration for QStack (inherits from QVector) (#2102) 2019-08-20 20:37:52 +02:00
Sebastian a2a874dbd5
gtk.cfg: Add/enhance function configurations and tests. (#2101)
Add/enhance:
g_once_init_enter(), g_once_init_leave() and g_signal_emit_by_name()
2019-08-20 15:00:30 +02:00
Sebastian 26dfee58f8
qt.cfg: Add QLinkedList container configuration and some tests. (#2099) 2019-08-20 07:09:43 +02:00
Daniel Marjamäki 530a1a1c68 Remove test/cfg/unmatchedSuppressionTest.c: This testing belongs better in test/cli. 2019-08-17 17:18:44 +02:00
Sebastian 544bedc6ee
qt.cfg: Add QByteArray container configuration (similar to QString) (#2088)
Reference: https://doc.qt.io/qt-5/qbytearray.html
2019-08-15 16:14:17 +02:00
Sebastian 81edb23c16
qt.cfg: Fix and enhance Qt container configuration (#2055)
-Add iterator end patterns
-Add/fix size and access functions
-Remove marking QList and QStringList as std-like strings
-QStringList configuration now inherits from QList like it is actually the case
-Add tests
2019-08-15 10:23:05 +02:00
versat 2519a1aed5 gnu.cfg: Add more __builtin_* functions and some tests
Most of them were detected by daca@home
2019-08-02 12:27:46 +02:00
Sebastian 5390588cda
gnu.cfg: Add xfree() (#2051)
It is hard to find good references, one that describes it a bit can
be found here:
https://manpages.ubuntu.com/manpages/bionic/man3/xmalloc.3pub.html

xfree() can be used instead of free().
A check, to verify that a memory leak is found if the memory allocated
via xmalloc() is not freed, has also been added.
2019-08-02 07:41:32 +02:00
Sebastian 549452b7b9
qt.cfg: Add container and function configurations for QVector (#2052)
Reference: https://doc.qt.io/qt-5/qvector.html
2019-07-31 13:58:55 +02:00
Rikard Falkeborn 8cd1d5a47d Use library for memleak checks (#2002)
* Use library for memleak checks

Change memleakOnRealloc and leakReturnValNotUsed to use library
configuration instead of hardcoding "realloc".

In order to do so, some care needs to be taken when matching for a
reallocation function, since it can no longer be assumed that the input
to be allocated is the first argument of the function. This complicates
getReallocationType() and checkReallocUsage() but is necessary in order
to handle for example freopen() properly.

Also, refactor memleakOnRealloc check to reduce duplicated code when
checking "a" and "*a". When doing so, extending the check to look for
arbitrary number of "*" can be done for free (just change an if
statement to a while statement). Most likely, this is an unusual case in
real world code.

* Remove redundant whitespace in Token::Match()

* Run on simplified checks

* Fix cppcheck warning
2019-07-22 10:37:36 +02:00
Rikard Falkeborn e19068504d Configure xrealloc and adjust gnu memory functions (#2003)
Remove <noreturn> tag, since the functions do not return unless there
was no error.
2019-07-16 08:12:21 +02:00
Rikard Falkeborn dcc375ca64 Update gtk memory functions (#2000)
* Improve configuration of g_try_realloc and g_try_realloc_n
* Mark g_realloc and similar functions as realloc functions
* Remove g_new, g_new0, etc as <alloc> functions, these are defined as
  macros and handled as the functions they're expanded to.
* Add tests. TODO tests will be resolved by using the library
  configuration in the checker.
2019-07-15 14:51:58 +02:00
Sebastian db43dcd601
posix.cfg: Add `<use-retval/>` to pthread_mutex_trylock (#1959)
Ignoring the return value of pthread_mutex_trylock is always a bug.
There is no other way to check if the mutex is locked or not after the
call.
2019-07-07 12:57:02 +02:00
Rikard Falkeborn 2bd026dd2a Add tests of std.cfg buffer size (#1958)
Includes a testcase for trac ticket #1379 which was fixed in
839fcddd8a.
2019-07-06 08:55:17 +02:00
Rikard Falkeborn 839fcddd8a Fix #6115 (Add support to realloc to cfg files) (#1953)
* Allow to configure realloc like functions

* memleakonrealloc: Bring back tests.

The old memleak checker was removed, and the tests for it was removed in
commit 9765a2dfab. This also removed the
tests for memleakOnRealloc. Bring back those tests, somewhat modified
since the checker no longer checks for memory leaks.

* Add realloc to mem leak check

* Add tests of realloc buffer size

* Configure realloc functions

* Add test of freopen

* Allow to configure which element is realloc argument

* Fix wrong close in test

cppcheck now warns for this

* Update manual

* Update docs

* Rename alloc/dalloc/realloc functions

Naming the member function realloc caused problems on appveyor. Rename
the alloc and dealloc functions as well for consistency.

* Change comparisson order

* Remove variable and use function call directly

* Create temporary variable to simplify

* Throw mismatchError on mismatching allocation/reallocation

* Refactor to separate function

* Fix potential nullptr dereference

As pointed out by cppcheck.
2019-07-05 12:44:52 +02:00
Sebastian c45dff1e1d
openmp.cfg: Add library configuration for OpenMP (#1956)
See https://www.openmp.org/
2019-07-05 03:00:52 +02:00
Rikard Falkeborn 60a213e6a5 Fix #9047 (c-style casts before malloc) (#1930)
* Fix #9047 (c-style casts before malloc)

Note that there are still no warnings for c++-style casts

* Fix memleak check with casts of assignments in if-statements

* Fix possible null pointer dereference

As pointed out by cppcheck.

* Add check of astOperand2 when removing casts

This is similar to how it is done in other checks.
2019-07-03 08:39:44 +02:00
Sebastian d745dcc0eb
gtk.cfg: Add g_error_*() functions (#1922) 2019-06-25 19:19:10 +02:00
orbitcowboy 02d307a231 posix.cfg: Added partial support for scandir() and a TODO comment. 2019-05-25 23:32:28 +02:00
orbitcowboy 4a9176f83c std.cfg: Added a test for tmpfile(). 2019-05-17 16:02:48 +02:00
Daniel Marjamäki e80181d35a astyle formatting
[ci skip]
2019-05-17 09:32:14 +02:00
orbitcowboy e48d785ea4 gnu.cfg: Added tests for mkostemp(), mkstemps() and mkostemps() functions. The test script 'test/cfg/runtests.sh' is now loading posix.cfg when checking gnu.cfg. Otherwise 'close()' was not available to Cppcheck, which lead to an error when 'make checkcfg' was executed. 2019-05-16 17:49:33 +02:00
orbitcowboy 719eb25ba9 posix.cfg: Improved configuration for 'mkstemp()' and added test cases to ensure resource leaks are caught. 2019-05-16 15:53:22 +02:00
Sebastian b1cb03b560
posix.c: Add test to avoid regression of already fixed ticket #9118 (#1820)
Trac ticket: https://trac.cppcheck.net/ticket/9118
Commit that likely fixed it already:
1b74bca973
2019-05-03 16:35:15 +02:00
orbitcowboy 45a3f679b4 posix.cfg: Improved configuration for close(). Issue a warning in case close is called with a file pointer having a negative value. 2019-04-21 12:28:17 +02:00
versat 974f01ce59 gtk.cfg: Add / improve g_str*() functions and add GTK_SIGNAL_FUNC(). 2019-04-01 16:15:32 +02:00
versat 9d8b965270 gtk.cfg: Add / improve g_string_*() function configurations.
daca@home reported missing configurations for most of them.
2019-04-01 15:33:27 +02:00
Sebastian 6976d5c6e2
gtk.cfg: Add support for g_new() and similar macros. (#1760)
Also add / improve corresponding function configurations and some tests.
2019-03-26 10:45:06 +01:00
orbitcowboy 9bfe7d74c0 windows.cfg: Fixed FP for invalidFunctionArg in second argument of _getcwd(). Reference: https://docs.microsoft.com/en-us/previous-versions/sf98bd4y(v%3Dvs.140) 2019-03-25 09:07:02 +01:00
versat 0d14bdac22 windows.cfg: Add "buffer-size" attributes, fix allocation configuration.
Memory allocated with `_aligned_*malloc*()` must be freed with
`_aligned_free*()`. Using `free()` is illegal.
See
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/aligned-malloc
for details.
Also add tests for some of the changed functions.
2019-03-22 13:11:03 +01:00
versat 7c09b0cfe0 gnu.cfg: Add "buffer-size" attribute and tests for xcalloc(). 2019-03-21 10:44:18 +01:00
versat 316475f79f std.cfg: Add "buffer-size" attribute and tests for aligned_alloc(). 2019-03-21 09:25:42 +01:00
versat 9b6b94336c gnu.cfg: Add buffer-size to xmalloc; add some __builtin_*() functions. 2019-03-19 15:24:02 +01:00
Sebastian 19e9e42dd7
Library: Enhance minsize configuration and allow simple values. (#1736)
Some POSIX and Windows functions require buffers of at least some
specific size. This is now possible to configure via for example this
minsize configuration: `<minsize type="value" value="26"/>`.
The range for valid buffer size values is 1 to LLONG_MAX
(9223372036854775807)
2019-03-17 14:22:26 +01:00
Daniel Marjamäki 87fe5c060e Refactoring of Null Pointer Checker 2019-03-16 21:21:30 +01:00
Daniel Marjamäki 34a8b2b519 Quick fix for 'make checkcfg' 2019-03-16 18:17:16 +01:00
versat 6f7612de03 boost.cfg: Add argument directions; some fixes; rearrange and document.
- Remove redundant function configurations for the same function since
it is not (yet) possible to configure overloaded functions. Instead mark
the optional arguments with `default="0"` so the configuration works
with a different number of arguments.
- Add documentation to boost.cfg (links and function declarations).
- Rearranged configurations so functions, defines, ... are together now.
- Add `direction` for function arguments where applicable.
- Add some tests to boost.cpp.
2019-03-15 11:13:08 +01:00
versat 3d02c10fde gnu.cfg: Further fixes, enhancements and adding argument directions. 2019-03-14 09:26:27 +01:00
Daniel Marjamäki cdeb91bfcc Travis: Restore the uint8_t arrays 2019-03-13 18:59:55 +01:00
Sebastian 1230357146
Library: Add initial configuration with tests for SQLite3 library. (#1737) 2019-03-13 13:57:40 +01:00
Daniel Marjamäki f9ce5b3407 Travis: quick fix for 'make checkcfg' 2019-03-13 09:30:59 +01:00
Daniel Marjamäki 27d750b3a1 Travis: Fix 'make checkcfg' 2019-03-11 13:43:15 +01:00
Daniel Marjamäki 7caa6628d5 Fix 'make checkcfg' 2019-03-09 15:41:07 +01:00
versat df73f7f355 std.cfg, windows.cfg: Move strcpy_s from windows.cfg to std.cfg.
strcpy_s belongs to the standard so it must be in std.cfg instead of
windows.cfg.
Configuration for strcpy_s has been improved and tests were added.
Found by daca@home
2019-03-05 15:33:16 +01:00
Sebastian 0934577dda
Library configuration: function argument direction fixes and enhancements (#1722)
* std.cfg: Add further argument directions (in, out, inout).

* testlibrary.cpp: Add test for function argument direction configuration.

* std.cfg: runastyle and add some more direction configurations.

* library.h: Add documentation for function argument direction enum.

* Do not use "direction" library information for pointer arguments.

Also fix further unmatched uninitvar messages in std configuration
tests.

* std.cfg: Add more argument direction configurations.

* test/cfg/std.c: Add test for argument direction configuration.

* astutils.cpp: Only ignore pointer arguments for out/inout arguments.

* library.h: Use suggested documentation for argument direction enum.
2019-03-04 22:57:40 +01:00
orbitcowboy 794d72d776 wxwidgets.cfg: Added more directions-attributes. 2019-03-04 10:26:37 +01:00
Daniel Marjamäki 5087f15035 Travis: Try to fix 'make checkcfg' 2019-03-02 19:38:11 +01:00
orbitcowboy 360823203f windows.cfg: Ensure the return value is taken into account for memory (re)-allocation functions. 2019-03-01 08:58:53 +01:00
versat f6c3749015 gtk.cfg: Add support for g_alloca() and g_newa().
References:
https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html#g-alloca
https://github.com/GNOME/glib/blob/master/glib/galloca.h
2019-02-28 15:29:37 +01:00
Martin Ettl fe402498e1 qt.cfg: Added support for Q_DECLARE_PUBLIC()-macro. 2019-02-27 15:38:31 +01:00
Martin Ettl 17c1733b0e gnu.cfg: Added support for asprintf() and vasprintf(). There is a FN with memory leak detection regarding pointer args, which is already mentioned in #8980. A comment has been added. 2019-02-27 15:17:34 +01:00
Sebastian 61f911d39a
qt.cfg: Add Q_DECLARE_TR_FUNCTIONS() and others (#1677)
Add unknownMacro Q_DECLARE_TR_FUNCTIONS found via daca@home.
Add function QCoreApplication::translate() and macro
QT_DECLARE_DEPRECATED_TR_FUNCTIONS() the unknownMacro depends on.
Reference:
https://doc.qt.io/qt-5/qcoreapplication.html#Q_DECLARE_TR_FUNCTIONS
https://doc.qt.io/qt-5/qcoreapplication.html#translate
2019-02-26 13:39:37 +01:00
versat dc63cb9f98 gtk.cfg: Add more details for g_print() and g_printerr()
Reference:
https://developer.gnome.org/glib/stable/glib-Warnings-and-Assertions.html#g-print
2019-02-18 16:48:46 +01:00
versat 4dae640e8c gtk.cfg: Add type conversion macros
Reference:
https://developer.gnome.org/glib/stable/glib-Type-Conversion-Macros.html
daca@home found that they are missing.
2019-02-15 08:44:21 +01:00
versat ed25ae3acb gtk.cfg: Add some configurations often reported as missing by daca@home
Add two g_assert*(), g_signal_connect_data(), some g_signal_connect*() functions and macros and g_strdup_printf().
2019-02-13 15:35:46 +01:00
versat fe6ea282d3 qt.cfg: Add support for QT_TR_NOOP* and QT_TRANSLATE_NOOP* macros
Reference:
https://doc.qt.io/qt-5/i18n-source-translation.html#using-qt-tr-noop-and-qt-translate-noop-in-c
2019-02-12 10:21:56 +01:00
versat 8207e48adc qt.cfg: Add support for macros Q_LIKELY and Q_UNLIKELY
Reference:
https://doc.qt.io/qt-5/qtglobal.html#Q_LIKELY
https://doc.qt.io/qt-5/qtglobal.html#Q_UNLIKELY
2019-02-12 08:21:49 +01:00
Sebastian 2c1f97d787
qt.cfg: Add support for macros `forever` and `Q_FOREVER` (#1662)
Reference:
https://doc.qt.io/qt-5/qtglobal.html#forever
https://doc.qt.io/qt-5/qtglobal.html#Q_FOREVER
2019-02-11 16:35:01 +01:00
Sebastian 3427e61383
std.cfg: Add support for std::string::assign() (#1660)
Reference: https://en.cppreference.com/w/cpp/string/basic_string/assign
2019-02-11 13:40:36 +01:00
Sebastian 5fe7aad5e3
qt.cfg: Add configuration and tests for macro Q_NULLPTR (#1651)
Qt defines `Q_NULLPTR` with `nullptr` if it is available, otherwise with `NULL`.
Since there seems to be no (sane) way to configure it the same way in the library configuration it is just defined with `NULL`.
2019-02-07 12:27:25 +01:00
Sebastian 55ce6d2073
qt.cfg: Add support and tests for QFile::exists function (#1645)
Found by daca@home
2019-02-06 13:23:05 +01:00
versat 62b9368b3c gtk.cfg: Add configurations for g_free() and g_malloc() / g_malloc0()
Reference: https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html
daca@home found these missing function configurations among others.
Also add tests for g_malloc() and g_free().
2019-01-28 13:47:46 +01:00
Sebastian b1f68229f2
Library cfg tests: Enable all tests again, exclude regressions for now (#1626)
Use `--check-library` for all tests as it was done before.
Re-enable all tests in runtests.sh again.
The regressions where runtests.sh would fail are disabled via "FIXME"
comment in the inline suppression comment.
2019-01-25 17:03:16 +01:00
Sebastian ce96ffd433
gtk.cfg: Add internationalization macros / functions (#1623)
Found via Donate CPU / daca@home.
Reference: https://developer.gnome.org/glib/stable/glib-I18N.html
Update header comment in gtk.cfg since it is now only edited manually.
2019-01-25 13:07:48 +01:00
Daniel Marjamäki c773e6ed10 runtests.sh: uncomment the xmlstarlet checking 2019-01-23 09:40:43 +01:00
Daniel Marjamäki 87489c3ffd Try to make Travis happy 2019-01-22 18:56:12 +01:00
Daniel Marjamäki f03ce97aae unmatched suppression: fix test case 2019-01-22 18:47:52 +01:00
versat 6f62b83fe6 checkcfg: Add regression test for umatchedSuppression errors
As discussed in https://trac.cppcheck.net/ticket/8931 a regression test is added
to the test/cfg/runtests.sh script to make sure that unmatchedSuppression messages result in an Cppcheck exit code that signals a failure.
2019-01-21 20:53:13 +01:00
Sebastian aa40e374ac
test/cfg/runtests.sh: Qt test: Fix syntax check when "-fPIC" is required (#1600)
On linux systems (like travis) Qt often seems to be built with the option "reduce_relocations" which requires an application using it to specify the option "-fPIC".
2019-01-14 17:48:04 +01:00
amai2012 2adf65968b posix.cfg: improve configuration for dlsym() 2019-01-12 21:50:02 +01:00
amai2012 400c6c8e76 Improve configuration for dlopen and add suitable test 2019-01-10 21:14:37 +01:00
amai2012 97bf5de133 Add more Windows (Microsoft) macros and a few lines of related test code 2019-01-08 21:15:04 +01:00
Sebastian 0aa4910244
Boost configuration: Add macros and initial test file (#1575) 2019-01-08 20:30:21 +01:00
Sebastian 7a59949cb4 qt config test: Use pkg-config to retrieve Qt settings. (#1571)
To be able to use real Qt-Code in "test/cfg/qt.cpp" and still do a
syntax check the Qt settings are read out via pkg-config now if it is
available. This way the test now can contain Qt macros and functions and
the syntax check can still be used.
Additionally the same options as for the other tests are used now for
the Qt config tests.
Installing the package "qtbase5-dev" should be enough to enable the
syntax checks (already installed for travis tests).
2019-01-07 14:40:21 +01:00
orbitcowboy 611eb81302 Fixed checkcfg: test/cfg/std.cpp:2904:error:uninitvar:Uninitialized variable: s 2018-12-23 18:09:55 +01:00
Daniel Marjamäki e6e3987935 snprintf/g_snprintf: do not allow uninitialized target buffer 2018-12-22 20:40:47 +01:00
amai2012 0f4eac657d Make script less verbose 2018-12-19 22:18:24 +01:00
Daniel Marjamäki 9742c1e2ae make checkcfg: Try to fix inline suppressions 2018-12-14 13:51:03 +01:00
Daniel Marjamäki 0b4e08cac9 Use FwdAnalysis in UnusedVar. This is still work-in-progress. Merging to master branch so it can be tested. 2018-12-13 18:52:56 +01:00
Daniel Marjamäki b7ca9bdc8d Travis: redundantCopy is not detected at the moment 2018-11-24 12:01:10 +01:00
Daniel Marjamäki ec89c7b1b8 Travis: redundantCopy is not detected at the moment 2018-11-24 11:27:27 +01:00
orbitcowboy ef05be2600 wxwidgets.cfg: Fixed FP due to overlaoded function wxSizer::Add(). 2018-11-23 09:49:08 +01:00
Daniel Marjamäki c181d28b1a astyle formatting
[ci skip]
2018-11-23 06:47:27 +01:00
orbitcowboy 428d0147bc wxwidgets.cfg: Added support for wxSizer::Add(). 2018-11-22 14:04:22 +01:00
orbitcowboy d6c85118a7 wxwidgets.cfg: Improved support for some wxStaticText member functions. 2018-11-22 13:47:17 +01:00
orbitcowboy 2b9bdc52d7 wxwidgets.cfg: Added support for wxWindow::Close() and derived classes. 2018-11-22 13:31:09 +01:00
orbitcowboy b4aa04db41 std.cfg: Added returnValue calculation for isless(), islessgreater() etc. 2018-11-20 16:58:33 +01:00
orbitcowboy 58b3d75b62 std.cfg: Added invalidFunctionArg cfg for strchr(). 2018-11-20 08:32:54 +01:00