Skip to content

Commit 1411b69

Browse files
committed
More cppcheck cleanup, missing initializations, suppressions, duplicate members
1 parent 3d707a6 commit 1411b69

10 files changed

Lines changed: 42 additions & 36 deletions

lib

src/ngscopeclient/HistoryDialog.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ string TimePoint::PrettyPrintDate() const
5151
if(offset > FS_PER_SECOND)
5252
{
5353
base += (offset / FS_PER_SECOND);
54+
55+
//cppcheck seems to think this is a divide by zero for some reason, it's obviously not
56+
//(FS_PER_SECOND is 1e15 which is only 50 bits long and comfortably fits in a signed int64)
57+
//cppcheck-suppress zerodiv
5458
offset = offset % (int64_t)FS_PER_SECOND;
5559
}
5660

@@ -79,6 +83,10 @@ string TimePoint::PrettyPrint() const
7983
if(offset > FS_PER_SECOND)
8084
{
8185
base += (offset / FS_PER_SECOND);
86+
87+
//cppcheck seems to think this is a divide by zero for some reason, it's obviously not
88+
//(FS_PER_SECOND is 1e15 which is only 50 bits long and comfortably fits in a signed int64)
89+
//cppcheck-suppress zerodiv
8290
offset = offset % (int64_t)FS_PER_SECOND;
8391
}
8492

@@ -103,11 +111,9 @@ string TimePoint::PrettyPrint() const
103111
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
104112
// Construction / destruction
105113

106-
HistoryDialog::HistoryDialog(HistoryManager& mgr, Session& session, MainWindow& wnd)
107-
: Dialog("History", "History", ImVec2(425, 350))
114+
HistoryDialog::HistoryDialog(HistoryManager& mgr, Session* session, MainWindow* wnd)
115+
: Dialog("History", "History", ImVec2(425, 350), session, wnd)
108116
, m_mgr(mgr)
109-
, m_session(session)
110-
, m_parent(wnd)
111117
, m_rowHeight(0)
112118
, m_selectionChanged(false)
113119
, m_selectedMarker(nullptr)
@@ -191,7 +197,7 @@ bool HistoryDialog::DoRender()
191197
}
192198

193199
//Force pin if we have a nickname or markers
194-
auto& markers = m_session.GetMarkers(point->m_time);
200+
auto& markers = m_session->GetMarkers(point->m_time);
195201
bool forcePin = false;
196202
if(!point->m_nickname.empty() || !markers.empty())
197203
{
@@ -297,7 +303,7 @@ bool HistoryDialog::DoRender()
297303
m_selectionChanged = true;
298304
}
299305

300-
m_parent.NavigateToTimestamp(m.m_offset);
306+
m_parent->NavigateToTimestamp(m.m_offset);
301307
}
302308

303309
if(ImGui::BeginPopupContextItem())
@@ -316,7 +322,7 @@ bool HistoryDialog::DoRender()
316322
//Nickname box
317323
ImGui::TableSetColumnIndex(2);
318324
if(ImGui::InputText("###nick", &m.m_name))
319-
m_parent.GetSession().OnMarkerChanged();
325+
m_session->OnMarkerChanged();
320326

321327
ImGui::PopID();
322328
}
@@ -325,7 +331,7 @@ bool HistoryDialog::DoRender()
325331
if(deletingMarker)
326332
{
327333
markers.erase(markers.begin() + markerToDelete);
328-
m_parent.GetSession().OnMarkerChanged();
334+
m_session->OnMarkerChanged();
329335
}
330336

331337
ImGui::TreePop();
@@ -344,8 +350,8 @@ bool HistoryDialog::DoRender()
344350

345351
//Delete the selected row
346352
//(manual delete applies even if we have markers or a pin)
347-
m_session.RemoveMarkers((*itDelete)->m_time);
348-
m_session.RemovePackets((*itDelete)->m_time);
353+
m_session->RemoveMarkers((*itDelete)->m_time);
354+
m_session->RemovePackets((*itDelete)->m_time);
349355
m_mgr.m_history.erase(itDelete);
350356

351357
if(deletedSelection)

src/ngscopeclient/HistoryDialog.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* *
33
* ngscopeclient *
44
* *
5-
* Copyright (c) 2012-2024 Andrew D. Zonenberg *
5+
* Copyright (c) 2012-2026 Andrew D. Zonenberg and contributors *
66
* All rights reserved. *
77
* *
88
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
@@ -46,7 +46,7 @@ class MainWindow;
4646
class HistoryDialog : public Dialog
4747
{
4848
public:
49-
HistoryDialog(HistoryManager& mgr, Session& session, MainWindow& wnd);
49+
HistoryDialog(HistoryManager& mgr, Session* session, MainWindow* wnd);
5050
virtual ~HistoryDialog();
5151

5252
virtual bool DoRender();
@@ -66,8 +66,6 @@ class HistoryDialog : public Dialog
6666

6767
protected:
6868
HistoryManager& m_mgr;
69-
Session& m_session;
70-
MainWindow& m_parent;
7169

7270
///@brief Height of a row in the dialog
7371
float m_rowHeight;

src/ngscopeclient/IGFDFileBrowser.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* *
33
* ngscopeclient *
44
* *
5-
* Copyright (c) 2012-2024 Andrew D. Zonenberg *
5+
* Copyright (c) 2012-2026 Andrew D. Zonenberg *
66
* All rights reserved. *
77
* *
88
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
@@ -55,7 +55,10 @@ IGFDFileBrowser::IGFDFileBrowser(
5555
//If linux read ~/.config/gtk-3.0/bookmarks
5656
//TODO: read bookmarks on other OSes
5757
#ifdef __linux__
58-
string home = getenv("HOME");
58+
string home;
59+
auto phome = getenv("HOME");
60+
if(phome)
61+
home = phome;
5962
string path = home + "/.config/gtk-3.0/bookmarks";
6063
FILE* fp = fopen(path.c_str(), "r");
6164
if(fp)

src/ngscopeclient/LogViewerDialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ bool LogViewerDialog::DoRender()
9292
ImGui::TableSetupColumn("Function", ImGuiTableColumnFlags_WidthStretch, 0.0f);
9393
ImGui::TableHeadersRow();
9494

95-
for(auto filter : g_trace_filters)
95+
for(auto& filter : g_trace_filters)
9696
{
9797
ImGui::TableNextRow(ImGuiTableRowFlags_None);
9898
ImGui::TableSetColumnIndex(0);

src/ngscopeclient/MainWindow.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ void MainWindow::ToolbarButtons()
10911091
ImGui::BeginDisabled();
10921092
if(ImGui::ImageButton("history", GetTexture("history"), buttonsize))
10931093
{
1094-
m_historyDialog = make_shared<HistoryDialog>(m_session.GetHistory(), m_session, *this);
1094+
m_historyDialog = make_shared<HistoryDialog>(m_session.GetHistory(), &m_session, this);
10951095
AddDialog(m_historyDialog);
10961096
}
10971097
if(hasHist)
@@ -2967,7 +2967,7 @@ bool MainWindow::LoadDialogs(const YAML::Node& node)
29672967
auto hist = node["history"];
29682968
if(hist && hist.as<bool>())
29692969
{
2970-
m_historyDialog = make_shared<HistoryDialog>(m_session.GetHistory(), m_session, *this);
2970+
m_historyDialog = make_shared<HistoryDialog>(m_session.GetHistory(), &m_session, this);
29712971
AddDialog(m_historyDialog);
29722972
}
29732973

@@ -2978,7 +2978,7 @@ bool MainWindow::LoadDialogs(const YAML::Node& node)
29782978
auto persist = node["persistence"];
29792979
if(persist && persist.as<bool>())
29802980
{
2981-
m_persistenceDialog = make_shared<PersistenceSettingsDialog>(*this);
2981+
m_persistenceDialog = make_shared<PersistenceSettingsDialog>(this);
29822982
AddDialog(m_persistenceDialog);
29832983
}
29842984

@@ -3579,7 +3579,7 @@ void MainWindow::SaveRecentFileList()
35793579
for(auto t : timestamps)
35803580
{
35813581
auto paths = reverseMap[t];
3582-
for(auto fpath : paths)
3582+
for(auto& fpath : paths)
35833583
{
35843584
YAML::Node child;
35853585
child["path"] = fpath;

src/ngscopeclient/MainWindow_Menus.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ void MainWindow::ViewMenu()
225225

226226
if(ImGui::MenuItem("Persistence Setup"))
227227
{
228-
m_persistenceDialog = make_shared<PersistenceSettingsDialog>(*this);
228+
m_persistenceDialog = make_shared<PersistenceSettingsDialog>(this);
229229
AddDialog(m_persistenceDialog);
230230
}
231231

@@ -645,7 +645,7 @@ void MainWindow::WindowMenu()
645645
ImGui::BeginDisabled();
646646
if(ImGui::MenuItem("History"))
647647
{
648-
m_historyDialog = make_shared<HistoryDialog>(m_session.GetHistory(), m_session, *this);
648+
m_historyDialog = make_shared<HistoryDialog>(m_session.GetHistory(), &m_session, this);
649649
AddDialog(m_historyDialog);
650650
}
651651
if(hasHistory)

src/ngscopeclient/PersistenceSettingsDialog.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/***********************************************************************************************************************
22
* *
3-
* glscopeclient *
3+
* ngscopeclient *
44
* *
5-
* Copyright (c) 2012-2023 Andrew D. Zonenberg *
5+
* Copyright (c) 2012-2026 Andrew D. Zonenberg and contributors *
66
* All rights reserved. *
77
* *
88
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
@@ -42,9 +42,8 @@ using namespace std;
4242
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4343
// Construction / destruction
4444

45-
PersistenceSettingsDialog::PersistenceSettingsDialog(MainWindow& parent)
46-
: Dialog("Persistence", "Persistence", ImVec2(600, 150))
47-
, m_parent(parent)
45+
PersistenceSettingsDialog::PersistenceSettingsDialog(MainWindow* parent)
46+
: Dialog("Persistence", "Persistence", ImVec2(600, 150), nullptr, parent)
4847
{
4948

5049
}
@@ -64,9 +63,9 @@ PersistenceSettingsDialog::~PersistenceSettingsDialog()
6463
*/
6564
bool PersistenceSettingsDialog::DoRender()
6665
{
67-
float decay = m_parent.GetPersistDecay();
66+
float decay = m_parent->GetPersistDecay();
6867
if(ImGui::SliderFloat("Decay Coefficient", &decay, 0, 1, "%.3f", ImGuiSliderFlags_AlwaysClamp))
69-
m_parent.SetPersistDecay(decay);
68+
m_parent->SetPersistDecay(decay);
7069

7170
return true;
7271
}

src/ngscopeclient/PersistenceSettingsDialog.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/***********************************************************************************************************************
22
* *
3-
* glscopeclient *
3+
* ngscopeclient *
44
* *
5-
* Copyright (c) 2012-2022 Andrew D. Zonenberg *
5+
* Copyright (c) 2012-2026 Andrew D. Zonenberg and contributors *
66
* All rights reserved. *
77
* *
88
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
@@ -41,13 +41,12 @@ class MainWindow;
4141
class PersistenceSettingsDialog : public Dialog
4242
{
4343
public:
44-
PersistenceSettingsDialog(MainWindow& parent);
44+
PersistenceSettingsDialog(MainWindow* parent);
4545
virtual ~PersistenceSettingsDialog();
4646

4747
virtual bool DoRender();
4848

4949
protected:
50-
MainWindow& m_parent;
5150
};
5251

5352
#endif

src/ngscopeclient/PowerSupplyDialog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* *
33
* ngscopeclient *
44
* *
5-
* Copyright (c) 2012-2024 Andrew D. Zonenberg and contributors *
5+
* Copyright (c) 2012-2026 Andrew D. Zonenberg and contributors *
66
* All rights reserved. *
77
* *
88
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
@@ -63,6 +63,7 @@ class PowerSupplyChannelUIState
6363
PowerSupplyChannelUIState()
6464
: m_outputEnabled(false)
6565
, m_overcurrentShutdownEnabled(false)
66+
, m_softStartEnabled(false)
6667
, m_setVoltage("")
6768
, m_setCurrent("")
6869
, m_committedSetVoltage(0)

0 commit comments

Comments
 (0)