18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-27 21:45:16 +01:00

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.
This commit is contained in:
jerrrrycho
2026-11-20 03:42:49 +01:00
committed by GitHub
parent 357ccabd0c
commit c2b034ddcd
3 changed files with 24 additions and 15 deletions

View File

@@ -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)

View File

@@ -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")
{

View File

@@ -211,15 +211,15 @@ void TGauge::Load( cParser &Parser, TDynamicObject const *Owner, double const mu
m_sourcemodel = nullptr;
std::array<TModel3d *, 2> 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;
}