From c2b034ddcdf3978ba452429c7fe217f9bc9d54b4 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Fri, 20 Nov 2026 03:42:49 +0100 Subject: [PATCH] refactor: no side effects in the right operand of && and || (Sonar S912) (#364) The ogl initialisation, the -resolution/-margin values of the standalone previews and the submodel lookups of TGauge::Load assign or increment in the right operand of && or ||. Each becomes plain statements which run exactly when the operand ran before: init_ogl() only when needs_ogl(), i advanced only when a value follows (and accepted), and the lookups by name and then by name + "_off" per model, in the same order, leaving submodel, submodelon and m_sourcemodel with the same values. --- application/application.cpp | 10 +++++++--- nodebank_previews_standalone.cpp | 6 ++++-- vehicle/Gauge.cpp | 23 +++++++++++++---------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/application/application.cpp b/application/application.cpp index 140475b60..2a024bfd6 100644 --- a/application/application.cpp +++ b/application/application.cpp @@ -393,10 +393,14 @@ int eu07_application::init(int Argc, char *Argv[]) ErrorLog("Failed to initialize glfw!"); return result; } - if (needs_ogl() && (result = init_ogl()) != 0) + if (needs_ogl()) { - ErrorLog("Failed to initialize ogl!"); - return result; + result = init_ogl(); + if (result != 0) + { + ErrorLog("Failed to initialize ogl!"); + return result; + } } if (crashreport_is_pending() && false == Global.test.enabled) diff --git a/nodebank_previews_standalone.cpp b/nodebank_previews_standalone.cpp index d94eb13ed..65c5e07f3 100644 --- a/nodebank_previews_standalone.cpp +++ b/nodebank_previews_standalone.cpp @@ -76,19 +76,21 @@ bool parse_arguments(int const Argc, char *Argv[], preview_settings &Settings) } else if (token == "-resolution") { - if ((i + 1 >= Argc) || (false == parse_number(Argv[++i], Settings.resolution)) || (Settings.resolution < 16)) + if ((i + 1 >= Argc) || (false == parse_number(Argv[i + 1], Settings.resolution)) || (Settings.resolution < 16)) { report("-resolution needs a number of pixels, 16 or more", true); return false; } + ++i; } else if (token == "-margin") { - if ((i + 1 >= Argc) || (false == parse_number(Argv[++i], Settings.margin)) || (Settings.margin < 0)) + if ((i + 1 >= Argc) || (false == parse_number(Argv[i + 1], Settings.margin)) || (Settings.margin < 0)) { report("-margin needs a number of pixels, 0 or more", true); return false; } + ++i; } else if (token == "-no-shadows") { diff --git a/vehicle/Gauge.cpp b/vehicle/Gauge.cpp index 6289fe5a2..c99448eed 100644 --- a/vehicle/Gauge.cpp +++ b/vehicle/Gauge.cpp @@ -211,15 +211,15 @@ void TGauge::Load( cParser &Parser, TDynamicObject const *Owner, double const mu m_sourcemodel = nullptr; std::array sources { Owner->mdKabina, Owner->mdLowPolyInt }; for( auto const *source : sources ) { - if( source != nullptr - && ( submodel = source->GetFromName( submodelname ) ) != nullptr ) { - // got what we wanted, bail out - m_sourcemodel = source; - break; + if( source == nullptr ) { + continue; } - // there's a possibility the default submodel was named with _off suffix - if( source != nullptr - && ( submodel = source->GetFromName( submodelname + "_off" ) ) != nullptr ) { + submodel = source->GetFromName( submodelname ); + if( submodel == nullptr ) { + // there's a possibility the default submodel was named with _off suffix + submodel = source->GetFromName( submodelname + "_off" ); + } + if( submodel != nullptr ) { // got what we wanted, bail out m_sourcemodel = source; break; @@ -231,8 +231,11 @@ void TGauge::Load( cParser &Parser, TDynamicObject const *Owner, double const mu // see if we can locate optional submodel for active state, with _on suffix TSubModel *submodelon { nullptr }; for( auto const *source : sources ) { - if( source != nullptr - && ( submodelon = source->GetFromName( submodelname + "_on" ) ) != nullptr ) { + if( source == nullptr ) { + continue; + } + submodelon = source->GetFromName( submodelname + "_on" ); + if( submodelon != nullptr ) { // got what we wanted, bail out break; }