Skip to content

Commit 3d707a6

Browse files
committed
Fixed more redundant variables and other cppcheck issues
1 parent d94fa6b commit 3d707a6

11 files changed

Lines changed: 39 additions & 36 deletions

lib

src/ngscopeclient/FilterPropertiesDialog.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* *
33
* ngscopeclient *
44
* *
5-
* Copyright (c) 2012-2025 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 *
@@ -317,7 +317,7 @@ bool FilterPropertiesDialog::DoParameter(FilterParameter& param, string name, ma
317317

318318
//Input path
319319
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 12);
320-
if(Dialog::UnitInputWithImplicitApply(name.c_str(), tempValues[name], nval, param.GetUnit()))
320+
if(Dialog::UnitInputWithImplicitApply(name, tempValues[name], nval, param.GetUnit()))
321321
{
322322
param.SetIntVal(nval);
323323
return true;
@@ -370,7 +370,7 @@ bool FilterPropertiesDialog::DoParameter(FilterParameter& param, string name, ma
370370
}
371371

372372
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 12);
373-
if(Dialog::Combo(name.c_str(), enumValues, nsel))
373+
if(Dialog::Combo(name, enumValues, nsel))
374374
{
375375
param.ParseString(enumValues[nsel]);
376376
return true;

src/ngscopeclient/LogViewerDialog.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* *
33
* ngscopeclient *
44
* *
5-
* Copyright (c) 2012-2025 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 *
@@ -45,8 +45,7 @@ extern GuiLogSink* g_guiLog;
4545
// Construction / destruction
4646

4747
LogViewerDialog::LogViewerDialog(MainWindow* parent)
48-
: Dialog("Log Viewer", "Log Viewer", ImVec2(500, 300))
49-
, m_parent(parent)
48+
: Dialog("Log Viewer", "Log Viewer", ImVec2(500, 300), nullptr, parent)
5049
, m_displayedSeverity(5)
5150
, m_severityFilter(Severity::DEBUG)
5251
, m_lastLine(0)

src/ngscopeclient/LogViewerDialog.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* *
33
* ngscopeclient *
44
* *
5-
* Copyright (c) 2012-2025 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 *
@@ -48,7 +48,6 @@ class LogViewerDialog : public Dialog
4848
virtual bool DoRender();
4949

5050
protected:
51-
MainWindow* m_parent;
5251

5352
//Displayed severity level
5453
int m_displayedSeverity;

src/ngscopeclient/MainWindow.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,7 @@ void MainWindow::NavigateToTimestamp(int64_t stamp, int64_t duration, StreamDesc
14701470

14711471
void MainWindow::ShowSyncWizard(shared_ptr<TriggerGroup> group, shared_ptr<Oscilloscope> secondary)
14721472
{
1473-
AddDialog(make_shared<ScopeDeskewWizard>(group, secondary, this, m_session));
1473+
AddDialog(make_shared<ScopeDeskewWizard>(group, secondary, this, &m_session));
14741474
}
14751475

14761476
void MainWindow::ShowManageInstruments()
@@ -3125,7 +3125,8 @@ void MainWindow::LoadLabNotes(const string& dataDir)
31253125
fseek(fp, 0, SEEK_SET);
31263126

31273127
auto buf = new char[len+1];
3128-
fread(buf, 1, len, fp);
3128+
if(len != fread(buf, 1, len, fp))
3129+
LogWarning("failed to read setup file %s\n", setupfile.c_str());
31293130
buf[len] = 0;
31303131

31313132
m_session.m_setupNotes = buf;
@@ -3144,7 +3145,8 @@ void MainWindow::LoadLabNotes(const string& dataDir)
31443145
fseek(fp, 0, SEEK_SET);
31453146

31463147
auto buf = new char[len+1];
3147-
fread(buf, 1, len, fp);
3148+
if(len != fread(buf, 1, len, fp))
3149+
LogWarning("failed to read lab notes file %s\n", genfile.c_str());
31483150
buf[len] = 0;
31493151

31503152
m_session.m_generalNotes = buf;

src/ngscopeclient/MainWindow_Menus.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void MainWindow::FileRecentMenu()
188188
for(auto t : timestamps)
189189
{
190190
auto paths = reverseMap[t];
191-
for(auto path : paths)
191+
for(auto& path : paths)
192192
{
193193
if(ImGui::BeginMenu(path.c_str()))
194194
{
@@ -472,7 +472,7 @@ void MainWindow::AddImportMenu()
472472
std::sort(sortedNames.begin(), sortedNames.end());
473473

474474
//Do all of the menu items
475-
for(auto fname : sortedNames)
475+
for(auto& fname : sortedNames)
476476
{
477477
//Hide everything but import filters
478478
if(fname.find("Import") == string::npos)
@@ -507,7 +507,7 @@ void MainWindow::AddGenerateMenu()
507507
std::sort(sortedNames.begin(), sortedNames.end());
508508

509509
//Do all of the menu items
510-
for(auto fname : sortedNames)
510+
for(auto& fname : sortedNames)
511511
{
512512
//Hide import filters
513513
if(fname.find("Import") != string::npos)

src/ngscopeclient/PacketManager.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ bool ProtocolDisplayFilter::Validate(const vector<string>& headers, bool nakedLi
408408
return false;
409409

410410
//Operators must make sense. For now only equal/unequal and boolean and/or allowed
411-
for(auto op : m_operators)
411+
for(auto& op : m_operators)
412412
{
413413
if( (op != "==") &&
414414
(op != "!=") &&
@@ -549,6 +549,8 @@ ProtocolDisplayFilterClause::ProtocolDisplayFilterClause(const string& str, size
549549
m_string += str[i];
550550
i++;
551551
}
552+
if(i >= str.length())
553+
return;
552554

553555
if(str[i] != '\"')
554556
m_type = TYPE_ERROR;
@@ -565,6 +567,8 @@ ProtocolDisplayFilterClause::ProtocolDisplayFilterClause(const string& str, size
565567
tmp += str[i];
566568
i++;
567569
}
570+
if(i >= str.length())
571+
return;
568572

569573
//Hex string
570574
if(tmp.find("0x") == 0)
@@ -598,6 +602,8 @@ ProtocolDisplayFilterClause::ProtocolDisplayFilterClause(const string& str, size
598602
m_identifier += str[i];
599603
i++;
600604
}
605+
if(i >= str.length())
606+
return;
601607

602608
//Opening square bracket
603609
if(str[i] == '[')
@@ -726,7 +732,7 @@ bool ProtocolDisplayFilterClause::Validate(const vector<string>& headers)
726732
//If we're an identifier, we must be a valid header field
727733
//TODO: support comparisons on data
728734
case TYPE_IDENTIFIER:
729-
for(auto h : headers)
735+
for(auto& h : headers)
730736
{
731737
//Match, removing spaces from header names if needed
732738
//Note that m_identifier is now the real, un-spaced version of the identifier name

src/ngscopeclient/SCPIConsoleDialog.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* *
33
* ngscopeclient *
44
* *
5-
* Copyright (c) 2012-2025 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 *
@@ -47,8 +47,9 @@ SCPIConsoleDialog::SCPIConsoleDialog(MainWindow* parent, shared_ptr<SCPIInstrume
4747
: Dialog(
4848
("SCPI Console: ") + inst->m_nickname,
4949
("SCPI Console: ") + inst->m_nickname,
50-
ImVec2(500, 300))
51-
, m_parent(parent)
50+
ImVec2(500, 300),
51+
nullptr,
52+
parent)
5253
, m_inst(inst)
5354
, m_commandPending(false)
5455
{

src/ngscopeclient/SCPIConsoleDialog.h

Lines changed: 1 addition & 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 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 *
@@ -55,7 +55,6 @@ class SCPIConsoleDialog : public Dialog
5555
{ return m_inst; }
5656

5757
protected:
58-
MainWindow* m_parent;
5958
std::shared_ptr<SCPIInstrument> m_inst;
6059

6160
std::vector<std::string> m_output;

src/ngscopeclient/ScopeDeskewWizard.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ ScopeDeskewWizard::ScopeDeskewWizard(
6363
shared_ptr<TriggerGroup> group,
6464
shared_ptr<Oscilloscope> secondary,
6565
MainWindow* parent,
66-
Session& session)
66+
Session* session)
6767
: Dialog(
6868
string("Deskew Oscilloscope: ") + secondary->m_nickname,
6969
"Deskew" + secondary->m_nickname,
70-
ImVec2(700, 400))
70+
ImVec2(700, 400),
71+
session,
72+
parent)
7173
, m_state(STATE_WELCOME_1)
7274
, m_group(group)
7375
, m_secondary(secondary)
74-
, m_parent(parent)
75-
, m_session(session)
7676
, m_useExtRefPrimary(true)
7777
, m_useExtRefSecondary(true)
7878
, m_measureCycle(0)
@@ -119,7 +119,7 @@ ScopeDeskewWizard::ScopeDeskewWizard(
119119
m_gpuCorrelationAvailable = g_hasShaderInt64;
120120

121121
//Clear out any existing skew calibration
122-
m_session.SetDeskew(m_secondary, 0);
122+
m_session->SetDeskew(m_secondary, 0);
123123
}
124124

125125
ScopeDeskewWizard::~ScopeDeskewWizard()
@@ -278,7 +278,7 @@ bool ScopeDeskewWizard::DoRender()
278278
//Record the current waveform timestamp on each channel (if any)
279279
//so we can check if new data has shown up
280280
{
281-
shared_lock<shared_mutex> lock(m_session.GetWaveformDataMutex());
281+
shared_lock<shared_mutex> lock(m_session->GetWaveformDataMutex());
282282
auto data = m_primaryStream.GetData();
283283
if(data)
284284
{
@@ -459,7 +459,7 @@ void ScopeDeskewWizard::DoMainProcessingFlow()
459459
{
460460
case STATE_ACQUIRE:
461461
{
462-
shared_lock<shared_mutex> lock(m_session.GetWaveformDataMutex());
462+
shared_lock<shared_mutex> lock(m_session->GetWaveformDataMutex());
463463

464464
//Make sure we have a waveform
465465
auto data = m_primaryStream.GetData();
@@ -516,7 +516,7 @@ void ScopeDeskewWizard::DoMainProcessingFlow()
516516

517517
if(ImGui::Button("Apply"))
518518
{
519-
m_session.SetDeskew(m_secondary, m_medianSkew);
519+
m_session->SetDeskew(m_secondary, m_medianSkew);
520520
m_state = STATE_CLOSE;
521521
}
522522
}
@@ -593,7 +593,7 @@ void ScopeDeskewWizard::StartCorrelation()
593593

594594
void ScopeDeskewWizard::DoProcessWaveformSparse(SparseAnalogWaveform* ppri, SparseAnalogWaveform* psec)
595595
{
596-
shared_lock<shared_mutex> lock(m_session.GetWaveformDataMutex());
596+
shared_lock<shared_mutex> lock(m_session->GetWaveformDataMutex());
597597

598598
//Calculate cross-correlation between the primary and secondary waveforms at up to +/- half the waveform length
599599
int64_t len = ppri->size();
@@ -765,7 +765,7 @@ void ScopeSyncWizard::DoProcessWaveformDensePackedEqualRateGeneric()
765765
*/
766766
void ScopeDeskewWizard::DoProcessWaveformUniformUnequalRate(UniformAnalogWaveform* ppri, UniformAnalogWaveform* psec)
767767
{
768-
shared_lock<shared_mutex> lock(m_session.GetWaveformDataMutex());
768+
shared_lock<shared_mutex> lock(m_session->GetWaveformDataMutex());
769769

770770
double start = GetTime();
771771

0 commit comments

Comments
 (0)