Skip to content

Commit f9ae57c

Browse files
committed
Fixed a bunch of static analysis warnings, some redundant variables, and a potential null dereference
1 parent 6cfe842 commit f9ae57c

9 files changed

Lines changed: 30 additions & 19 deletions

src/ngscopeclient/ProtocolAnalyzerDialog.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* *
33
* ngscopeclient *
44
* *
5-
* Copyright (c) 2012-2025 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 *
@@ -337,7 +337,11 @@ bool ProtocolAnalyzerDialog::DoRender()
337337
ImVec2(0, 0)))
338338
{
339339
m_selectedPacket = pack;
340+
341+
//row is now selected, we may or may not do something with this flag but write it for consistency
342+
//cppcheck-suppress deadcode.DeadStores
340343
rowIsSelected = true;
344+
341345
visibleRowSelected = true;
342346

343347
//See if a new waveform was selected

src/ngscopeclient/Session.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ bool Session::LoadWaveformDataForScope(
855855
return true;
856856
}
857857

858-
void Session::DoLoadWaveformDataForStream(WaveformBase* cap, string format, string fname)
858+
void Session::DoLoadWaveformDataForStream(WaveformBase* cap, const string& format, const string& fname)
859859
{
860860
auto sacap = dynamic_cast<SparseAnalogWaveform*>(cap);
861861
auto uacap = dynamic_cast<UniformAnalogWaveform*>(cap);

src/ngscopeclient/Session.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ class Session
422422
int version,
423423
const YAML::Node& node,
424424
const std::string& dataDir);
425-
void DoLoadWaveformDataForStream(WaveformBase* cap, std::string format, std::string fname);
425+
void DoLoadWaveformDataForStream(WaveformBase* cap, const std::string& format, const std::string& fname);
426426
bool ConvertLegacyUniformWaveforms();
427427

428428
///@brief Version of the file being loaded

src/ngscopeclient/StreamBrowserDialog.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ void StreamBrowserDialog::renderDmmProperties(std::shared_ptr<Multimeter> dmm, M
689689
int modeSelector = 0;
690690
for(unsigned int i=0; i<32; i++)
691691
{
692-
auto mode = static_cast<Multimeter::MeasurementTypes>(1 << i);
692+
auto mode = static_cast<Multimeter::MeasurementTypes>(1U << i);
693693
if(modemask & mode)
694694
{
695695
modes.push_back(mode);
@@ -1339,8 +1339,13 @@ void StreamBrowserDialog::DoFrequencySettings(shared_ptr<Oscilloscope> scope)
13391339
void StreamBrowserDialog::DoSpectrometerSettings(shared_ptr<SCPISpectrometer> spec)
13401340
{
13411341
auto scope = dynamic_pointer_cast<SCPIOscilloscope>(spec);
1342+
1343+
//Create the object only when necessary
1344+
//cppcheck doesn't like this but doesn't realize we're creating a new object if it's not there already
1345+
//cppcheck-suppress stlFindInsert
13421346
if(m_timebaseConfig.find(scope) == m_timebaseConfig.end())
13431347
m_timebaseConfig[scope] = make_shared<StreamBrowserTimebaseInfo>(scope);
1348+
13441349
auto config = m_timebaseConfig[scope];
13451350

13461351
auto width = ImGui::GetFontSize() * 5;

src/ngscopeclient/TriggerPropertiesDialog.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void TriggerPropertiesPage::Render(bool graphEditorMode)
154154
}
155155

156156
//The actual combo box
157-
if(Dialog::Combo(trig->GetInputName(i).c_str(), names, sel))
157+
if(Dialog::Combo(trig->GetInputName(i), names, sel))
158158
{
159159
trig->SetInput(i, matchingInputs[sel]);
160160
updated = true;
@@ -262,8 +262,7 @@ void TriggerPropertiesPage::FindAllStreams(vector<StreamDescriptor>& streams)
262262
// Construction / destruction
263263

264264
TriggerPropertiesDialog::TriggerPropertiesDialog(Session* session)
265-
: Dialog("Trigger", "Trigger", ImVec2(300, 400))
266-
, m_session(session)
265+
: Dialog("Trigger", "Trigger", ImVec2(300, 400), session)
267266
{
268267
Refresh();
269268
}

src/ngscopeclient/TriggerPropertiesDialog.h

Lines changed: 1 addition & 3 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 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 *
@@ -76,8 +76,6 @@ class TriggerPropertiesDialog : public Dialog
7676
virtual bool DoRender();
7777

7878
protected:
79-
Session* m_session;
80-
8179
std::vector<std::unique_ptr<TriggerPropertiesPage>> m_pages;
8280
std::vector<int> m_triggerTypeIndexes;
8381
};

src/ngscopeclient/WaveformArea.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,10 @@ void WaveformArea::RenderSpectrumPeaks(ImDrawList* list, shared_ptr<DisplayedCha
15021502
else
15031503
npeak.m_labelYpos = p.m_y - PixelsToYAxisUnits(3*ImGui::GetFontSize());
15041504

1505+
//Default sizes to 0 until we render it, just so we don't have uninitialized junk floating around
1506+
npeak.m_labelXsize = 0;
1507+
npeak.m_labelYsize = 0;
1508+
15051509
//Default to 100% alpha
15061510
npeak.m_peakAlpha = 255;
15071511

@@ -3078,13 +3082,11 @@ void WaveformArea::CheckForScaleMismatch(ImVec2 start, ImVec2 size)
30783082
//If the mismatched stream isn't part of a scope, don't bother showing any warnings etc
30793083
//Filters can't be overdriven, so just silently clip
30803084
auto ochan = dynamic_cast<OscilloscopeChannel*>(mismatchStream.m_channel);
3081-
Oscilloscope* scope = nullptr;
3082-
if(ochan)
3083-
{
3084-
scope = ochan->GetScope();
3085-
if(!scope)
3086-
return;
3087-
}
3085+
if(!ochan)
3086+
return;
3087+
auto scope = ochan->GetScope();
3088+
if(!scope)
3089+
return;
30883090

30893091
//If we get here, we had a mismatch. Prepare to draw the warning message centered in the plot
30903092
//above everything else
@@ -4138,7 +4140,7 @@ void WaveformArea::ChannelButton(shared_ptr<DisplayedChannel> chan, size_t index
41384140
ImVec2 gradsize(8*height, height);
41394141

41404142
auto list = ImGui::GetWindowDrawList();
4141-
for(auto internalName : gradients)
4143+
for(auto& internalName : gradients)
41424144
{
41434145
auto displayName = m_parent->GetEyeGradientFriendlyName(internalName);
41444146

src/ngscopeclient/ngscopeclient.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ class Session;
5858
class InstrumentThreadArgs
5959
{
6060
public:
61+
6162
InstrumentThreadArgs(std::shared_ptr<SCPIInstrument> p, Session* sess)
6263
: inst(p)
64+
, shuttingDown(nullptr) //initialize here to avoid static analysis warning, but must be overwritten
65+
//with a valid shutdown flag pointer before spawning the InstrumentThread
6366
, session(sess)
6467
{}
6568

0 commit comments

Comments
 (0)