2018-02-06 15:33:45 +01:00
|
|
|
|
2018-02-20 23:34:01 +01:00
|
|
|
// Test library configuration for wxwidgets.cfg
|
2018-02-06 15:33:45 +01:00
|
|
|
//
|
|
|
|
// Usage:
|
2018-02-20 23:34:01 +01:00
|
|
|
// $ ./cppcheck --check-library --enable=information --enable=style --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr '--template="{file}:{line}:{severity}:{id}:{message}"' --inconclusive --library=wxwidgets -f test/cfg/wxwidgets.cpp
|
2018-02-06 15:33:45 +01:00
|
|
|
// =>
|
|
|
|
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
|
|
|
|
//
|
|
|
|
|
2018-02-09 20:34:15 +01:00
|
|
|
#include <wx/app.h>
|
|
|
|
#include <wx/log.h>
|
2018-02-06 15:33:45 +01:00
|
|
|
#include <wx/filefn.h>
|
2018-02-09 20:34:15 +01:00
|
|
|
#include <wx/spinctrl.h>
|
|
|
|
#include <wx/artprov.h>
|
|
|
|
#include <wx/calctrl.h>
|
|
|
|
#include <wx/combo.h>
|
|
|
|
#include <wx/icon.h>
|
|
|
|
#include <wx/bitmap.h>
|
2018-02-14 09:53:40 +01:00
|
|
|
#include <wx/dataview.h>
|
2018-02-20 23:34:01 +01:00
|
|
|
#include <wx/memory.h>
|
2018-03-31 13:23:12 +02:00
|
|
|
#include <wx/frame.h>
|
|
|
|
#include <wx/menu.h>
|
2018-11-22 13:47:17 +01:00
|
|
|
#include <wx/stattext.h>
|
2018-11-22 14:04:22 +01:00
|
|
|
#include <wx/sizer.h>
|
2019-08-23 19:10:49 +02:00
|
|
|
#include <wx/string.h>
|
2018-02-06 15:33:45 +01:00
|
|
|
|
|
|
|
void validCode()
|
|
|
|
{
|
|
|
|
wxString str = wxGetCwd();
|
2018-12-13 18:52:56 +01:00
|
|
|
(void)str;
|
2018-02-06 15:33:45 +01:00
|
|
|
|
|
|
|
wxLogGeneric(wxLOG_Message, "test %d", 0);
|
|
|
|
wxLogMessage("test %s", "str");
|
|
|
|
|
|
|
|
wxString translation1 = _("text");
|
|
|
|
wxString translation2 = wxGetTranslation("text");
|
|
|
|
wxString translation3 = wxGetTranslation("string", "domain");
|
2018-12-13 18:52:56 +01:00
|
|
|
(void)translation1;
|
|
|
|
(void)translation2;
|
|
|
|
(void)translation3;
|
2018-02-06 15:33:45 +01:00
|
|
|
}
|
|
|
|
|
2018-02-09 20:34:15 +01:00
|
|
|
#if wxUSE_GUI==1
|
|
|
|
void validGuiCode()
|
|
|
|
{
|
|
|
|
#if wxUSE_SPINCTRL==1
|
|
|
|
extern wxSpinCtrl spinCtrlInstance;
|
|
|
|
spinCtrlInstance.SetBase(10);
|
|
|
|
spinCtrlInstance.SetBase(16);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-04-07 20:27:02 +02:00
|
|
|
void nullPointer(const wxString &str)
|
2018-02-06 15:33:45 +01:00
|
|
|
{
|
2019-03-16 21:21:30 +01:00
|
|
|
// cppcheck-suppress nullPointer
|
2018-02-09 20:34:15 +01:00
|
|
|
wxLogGeneric(wxLOG_Message, (char*)NULL);
|
2019-03-16 21:21:30 +01:00
|
|
|
// cppcheck-suppress nullPointer
|
2018-02-09 20:34:15 +01:00
|
|
|
wxLogMessage((char*)NULL);
|
2018-04-07 20:27:02 +02:00
|
|
|
|
|
|
|
double *doublePtr = NULL;
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)str.ToDouble(doublePtr);
|
2019-03-04 10:26:37 +01:00
|
|
|
double *doublePtr1 = NULL;
|
2018-04-07 20:27:02 +02:00
|
|
|
// cppcheck-suppress nullPointer
|
2019-03-04 10:26:37 +01:00
|
|
|
(void)str.ToCDouble(doublePtr1);
|
2018-04-07 20:27:02 +02:00
|
|
|
|
|
|
|
long * longPtr = NULL;
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)str.ToLong(longPtr);
|
2019-03-04 10:26:37 +01:00
|
|
|
long * longPtr1 = NULL;
|
2018-04-07 20:27:02 +02:00
|
|
|
// cppcheck-suppress nullPointer
|
2019-03-04 10:26:37 +01:00
|
|
|
(void)str.ToCLong(longPtr1);
|
2018-04-07 20:27:02 +02:00
|
|
|
|
|
|
|
unsigned long * ulongPtr = NULL;
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)str.ToULong(ulongPtr);
|
2019-03-04 10:26:37 +01:00
|
|
|
unsigned long * ulongPtr1 = NULL;
|
2018-04-07 20:27:02 +02:00
|
|
|
// cppcheck-suppress nullPointer
|
2019-03-04 10:26:37 +01:00
|
|
|
(void)str.ToCULong(ulongPtr1);
|
2018-04-07 20:27:02 +02:00
|
|
|
|
|
|
|
long long * longLongPtr = NULL;
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)str.ToLongLong(longLongPtr);
|
|
|
|
|
|
|
|
unsigned long long * ulongLongPtr = NULL;
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)str.ToULongLong(ulongLongPtr);
|
2018-11-22 14:04:22 +01:00
|
|
|
}
|
2018-04-07 20:27:02 +02:00
|
|
|
|
2018-11-22 14:04:22 +01:00
|
|
|
void nullPointer_wxSizer_Add(wxSizer &sizer, wxWindow *w)
|
|
|
|
{
|
2018-11-23 06:47:27 +01:00
|
|
|
wxWindow * const ptr = 0;
|
2018-11-23 09:49:08 +01:00
|
|
|
// @todo cppcheck-suppress nullPointer
|
2018-11-23 06:47:27 +01:00
|
|
|
sizer.Add(ptr);
|
|
|
|
// No warning shall be issued for
|
|
|
|
sizer.Add(w);
|
2018-11-22 14:04:22 +01:00
|
|
|
}
|
|
|
|
|
2018-11-23 06:47:27 +01:00
|
|
|
void uninitvar_wxSizer_Add(wxSizer &sizer, wxWindow *w,wxObject* userData)
|
2018-11-22 14:04:22 +01:00
|
|
|
{
|
2019-03-02 19:38:11 +01:00
|
|
|
int uninit1, uninit2, uninit3;
|
2018-11-23 06:47:27 +01:00
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-02 19:38:11 +01:00
|
|
|
sizer.Add(w,uninit1);
|
2018-11-23 06:47:27 +01:00
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-02 19:38:11 +01:00
|
|
|
sizer.Add(w,4,uninit2);
|
2018-11-23 06:47:27 +01:00
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-02 19:38:11 +01:00
|
|
|
sizer.Add(w,4,2,uninit3,userData);
|
2018-02-06 15:33:45 +01:00
|
|
|
}
|
|
|
|
|
2018-04-04 21:29:55 +02:00
|
|
|
void ignoredReturnValue(const wxString &s)
|
2018-02-06 15:33:45 +01:00
|
|
|
{
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
wxGetCwd();
|
2018-04-04 21:29:55 +02:00
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
wxAtoi(s);
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
wxAtol(s);
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
wxAtof(s);
|
2018-02-06 15:33:45 +01:00
|
|
|
}
|
|
|
|
|
2018-04-07 20:27:02 +02:00
|
|
|
void invalidFunctionArg(const wxString &str)
|
2018-02-06 15:33:45 +01:00
|
|
|
{
|
2018-02-09 20:34:15 +01:00
|
|
|
#if wxUSE_SPINCTRL==1
|
|
|
|
extern wxSpinCtrl spinCtrlInstance;
|
2018-02-06 15:33:45 +01:00
|
|
|
// cppcheck-suppress invalidFunctionArg
|
2018-02-09 20:34:15 +01:00
|
|
|
spinCtrlInstance.SetBase(0);
|
2018-02-06 15:33:45 +01:00
|
|
|
// cppcheck-suppress invalidFunctionArg
|
2018-02-09 20:34:15 +01:00
|
|
|
spinCtrlInstance.SetBase(5);
|
|
|
|
#endif
|
2018-04-07 20:27:02 +02:00
|
|
|
|
|
|
|
long l;
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)str.ToLong(&l, -1);
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)str.ToLong(&l, 1);
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)str.ToLong(&l, 37);
|
2018-02-06 15:33:45 +01:00
|
|
|
}
|
|
|
|
|
2018-11-22 13:31:09 +01:00
|
|
|
void uninitvar(wxWindow &w)
|
2018-02-06 15:33:45 +01:00
|
|
|
{
|
|
|
|
wxLogLevel logLevelUninit;
|
|
|
|
char cBufUninit[10];
|
|
|
|
char *pcUninit;
|
2018-11-22 13:31:09 +01:00
|
|
|
bool uninitBool;
|
2018-02-06 15:33:45 +01:00
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
wxLogGeneric(logLevelUninit, "test");
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
wxLogMessage(cBufUninit);
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
wxLogMessage(pcUninit);
|
2018-11-22 13:31:09 +01:00
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
w.Close(uninitBool);
|
2018-04-07 20:27:02 +02:00
|
|
|
}
|
|
|
|
|
2018-11-22 13:47:17 +01:00
|
|
|
void uninitvar_wxStaticText(wxStaticText &s)
|
|
|
|
{
|
|
|
|
// no warning
|
|
|
|
s.Wrap(-1);
|
|
|
|
bool uninitBool;
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
s.Wrap(uninitBool);
|
|
|
|
}
|
|
|
|
|
2018-04-07 20:27:02 +02:00
|
|
|
void uninitvar_wxString_NumberConversion(const wxString &str, const int numberBase)
|
|
|
|
{
|
2019-03-02 19:38:11 +01:00
|
|
|
int uninitInteger1;
|
|
|
|
int uninitInteger2;
|
|
|
|
int uninitInteger3;
|
|
|
|
int uninitInteger4;
|
|
|
|
int uninitInteger5;
|
|
|
|
int uninitInteger6;
|
2018-04-07 20:27:02 +02:00
|
|
|
long l;
|
|
|
|
long long ll;
|
|
|
|
unsigned long ul;
|
|
|
|
unsigned long long ull;
|
|
|
|
|
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-02 19:38:11 +01:00
|
|
|
(void)str.ToLong(&l, uninitInteger1);
|
2018-04-04 21:29:55 +02:00
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-02 19:38:11 +01:00
|
|
|
(void)str.ToLongLong(&ll, uninitInteger2);
|
2018-04-07 20:27:02 +02:00
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-02 19:38:11 +01:00
|
|
|
(void)str.ToULong(&ul, uninitInteger3);
|
2018-04-07 20:27:02 +02:00
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-02 19:38:11 +01:00
|
|
|
(void)str.ToULongLong(&ull, uninitInteger4);
|
2018-04-07 20:27:02 +02:00
|
|
|
|
2018-04-04 21:29:55 +02:00
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-02 19:38:11 +01:00
|
|
|
(void)str.ToCLong(&l, uninitInteger5);
|
2018-04-04 21:29:55 +02:00
|
|
|
// cppcheck-suppress uninitvar
|
2019-03-02 19:38:11 +01:00
|
|
|
(void)str.ToCULong(&ul, uninitInteger6);
|
2018-02-06 15:33:45 +01:00
|
|
|
}
|
2018-02-07 11:40:42 +01:00
|
|
|
|
2018-03-31 13:34:40 +02:00
|
|
|
void uninitvar_SetMenuBar(wxFrame * const framePtr, wxMenuBar * const menuBarPtr)
|
2018-03-31 13:23:12 +02:00
|
|
|
{
|
2018-03-31 13:49:47 +02:00
|
|
|
wxMenuBar *menuBar;
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
framePtr->SetMenuBar(menuBar);
|
2018-03-31 13:23:12 +02:00
|
|
|
framePtr->SetMenuBar(menuBarPtr);
|
2018-03-31 13:34:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void uninitvar_wxMenuBarAppend(wxMenuBar * const menuBarPtr, wxMenu * const menuPtr, const wxString &title)
|
|
|
|
{
|
2018-03-31 13:49:47 +02:00
|
|
|
wxMenu *menu;
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
menuBarPtr->Append(menu, title);
|
2018-03-31 13:34:40 +02:00
|
|
|
menuBarPtr->Append(menuPtr, title);
|
2018-03-31 13:49:47 +02:00
|
|
|
}
|
2018-03-31 13:23:12 +02:00
|
|
|
|
2018-02-14 09:53:40 +01:00
|
|
|
void deprecatedFunctions_wxDataViewCustomRenderer(wxDataViewCustomRenderer &dataViewCustomRenderer, wxPoint cursor, wxRect cell, wxDataViewModel *model, const wxDataViewItem &item, unsigned int col)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress ActivateCalled
|
|
|
|
dataViewCustomRenderer.Activate(cell, model, item, col);
|
|
|
|
// cppcheck-suppress LeftClickCalled
|
|
|
|
dataViewCustomRenderer.LeftClick(cursor, cell, model, item, col);
|
|
|
|
}
|
|
|
|
|
|
|
|
void deprecatedFunctions(wxApp &a,
|
|
|
|
const wxString &s,
|
|
|
|
wxArtProvider *artProvider,
|
|
|
|
wxCalendarCtrl &calenderCtrl,
|
2018-02-20 23:34:01 +01:00
|
|
|
wxComboCtrl &comboCtrl,
|
|
|
|
wxChar * path)
|
2018-02-07 11:40:42 +01:00
|
|
|
{
|
2018-02-09 20:34:15 +01:00
|
|
|
#ifdef __WXOSX__
|
2018-02-07 11:40:42 +01:00
|
|
|
// cppcheck-suppress MacOpenFileCalled
|
|
|
|
a.MacOpenFile(s);
|
2018-02-09 20:34:15 +01:00
|
|
|
#endif
|
2018-02-11 16:58:39 +01:00
|
|
|
|
|
|
|
#if wxCHECK_VERSION(3, 1, 0) // wxWidets-3.1.0 or higher:
|
|
|
|
// Some functions are not available anymore in newer versions
|
|
|
|
|
|
|
|
// @todo cppcheck-suppress ShowPopupCalled
|
|
|
|
comboCtrl.ShowPopup();
|
|
|
|
#else
|
2018-02-07 11:40:42 +01:00
|
|
|
// cppcheck-suppress InsertCalled
|
|
|
|
wxArtProvider::Insert(artProvider);
|
2018-02-11 16:58:39 +01:00
|
|
|
|
|
|
|
// cppcheck-suppress GetTextIndentCalled
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
comboCtrl.GetTextIndent();
|
|
|
|
|
|
|
|
// cppcheck-suppress HidePopupCalled
|
|
|
|
comboCtrl.HidePopup(true);
|
|
|
|
// cppcheck-suppress HidePopupCalled
|
|
|
|
comboCtrl.HidePopup(false);
|
|
|
|
// cppcheck-suppress HidePopupCalled
|
|
|
|
comboCtrl.HidePopup(/*default=false*/);
|
|
|
|
|
|
|
|
// cppcheck-suppress SetTextIndentCalled
|
|
|
|
comboCtrl.SetTextIndent(0);
|
2018-02-20 23:34:01 +01:00
|
|
|
|
2018-02-21 12:20:56 +01:00
|
|
|
#if wxUSE_DEBUG_CONTEXT==1
|
2018-02-20 23:34:01 +01:00
|
|
|
// cppcheck-suppress GetLevelCalled
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
wxDebugContext::GetLevel();
|
|
|
|
// cppcheck-suppress SetLevelCalled
|
|
|
|
wxDebugContext::SetLevel(42);
|
2018-02-21 12:20:56 +01:00
|
|
|
#endif
|
2018-02-20 23:34:01 +01:00
|
|
|
|
|
|
|
// cppcheck-suppress wxDos2UnixFilenameCalled
|
|
|
|
wxDos2UnixFilename(path);
|
|
|
|
|
|
|
|
// cppcheck-suppress wxFileNameFromPathCalled
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
2018-02-21 12:20:56 +01:00
|
|
|
wxFileNameFromPath(wxT_2("../test.c"));
|
2018-02-11 16:58:39 +01:00
|
|
|
#endif
|
|
|
|
|
2018-02-09 20:34:15 +01:00
|
|
|
#if defined(__WXMSW__) || defined(__WXGTK__)
|
|
|
|
// EnableYearChange() is not available on these GUI systems
|
|
|
|
#else
|
2018-02-07 13:33:15 +01:00
|
|
|
// cppcheck-suppress EnableYearChangeCalled
|
|
|
|
calenderCtrl.EnableYearChange(false);
|
|
|
|
// cppcheck-suppress EnableYearChangeCalled
|
2018-02-11 16:58:39 +01:00
|
|
|
calenderCtrl.EnableYearChange(true);
|
|
|
|
// cppcheck-suppress EnableYearChangeCalled
|
2018-02-07 13:33:15 +01:00
|
|
|
calenderCtrl.EnableYearChange(/*default=yes*/);
|
2018-02-09 20:34:15 +01:00
|
|
|
#endif
|
2018-02-07 11:40:42 +01:00
|
|
|
}
|
2019-08-23 19:10:49 +02:00
|
|
|
|
|
|
|
void wxString_test1(wxString s)
|
|
|
|
{
|
|
|
|
for (int i = 0; i <= s.size(); ++i) {
|
|
|
|
// cppcheck-suppress stlOutOfBounds
|
|
|
|
s[i] = 'x';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxString_test2()
|
|
|
|
{
|
|
|
|
wxString s;
|
|
|
|
// cppcheck-suppress containerOutOfBounds
|
|
|
|
s[1] = 'a';
|
|
|
|
s.append("abc");
|
|
|
|
s[1] = 'B';
|
|
|
|
printf("%s", static_cast<const char*>(s.c_str()));
|
|
|
|
wxPrintf("%s", s);
|
|
|
|
wxPrintf("%s", s.c_str());
|
|
|
|
s.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString::iterator wxString_test3()
|
|
|
|
{
|
|
|
|
wxString wxString1;
|
|
|
|
wxString wxString2;
|
|
|
|
// cppcheck-suppress iterators2
|
|
|
|
for (wxString::iterator it = wxString1.begin(); it != wxString2.end(); ++it)
|
|
|
|
{}
|
|
|
|
|
|
|
|
wxString::iterator it = wxString1.begin();
|
|
|
|
// cppcheck-suppress returnDanglingLifetime
|
|
|
|
return it;
|
|
|
|
}
|