From c82cc0d4a444e818468ca9005e83c9e9b26d1bc5 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sat, 10 Oct 2026 17:52:59 +0200 Subject: [PATCH] refactor(sonar): more small fixes - std::format instead of iostream manipulators in to_string/to_hex_str (cpp:S6495); output verified identical, negative hex values keep the unsigned form - remove an empty compound statement (cpp:S108) - drop an always-false unsigned < 0 branch (cpp:S1768) - explicit lambda capture (cpp:S3608) - std::make_unique (cpp:S5950) Co-Authored-By: Claude Opus 5.5 --- application/driverhints.cpp | 2 +- rendering/nullrenderer.cpp | 2 +- simulation/simulationtime.cpp | 2 +- utilities/utilities.cpp | 13 ++++--------- vehicle/Train.cpp | 2 -- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/application/driverhints.cpp b/application/driverhints.cpp index 78e000f5..bcfd7dbd 100644 --- a/application/driverhints.cpp +++ b/application/driverhints.cpp @@ -38,7 +38,7 @@ void TController::remove_hint( driver_hint const Value ) { m_hints.remove_if( - [=]( auto const &Hint ) { + [Value]( auto const &Hint ) { return std::get(Hint) == Value; } ); } diff --git a/rendering/nullrenderer.cpp b/rendering/nullrenderer.cpp index a37eddb9..332d357c 100644 --- a/rendering/nullrenderer.cpp +++ b/rendering/nullrenderer.cpp @@ -3,7 +3,7 @@ std::unique_ptr null_renderer::create_func() { - return std::unique_ptr(new null_renderer()); + return std::make_unique(); } bool null_renderer::renderer_register = gfx_renderer_factory::get_instance()->register_backend("null", null_renderer::create_func); diff --git a/simulation/simulationtime.cpp b/simulation/simulationtime.cpp index 4c6246d5..d2f8b26c 100644 --- a/simulation/simulationtime.cpp +++ b/simulation/simulationtime.cpp @@ -167,7 +167,7 @@ scenario_time::daymonth( WORD &Day, WORD &Month, WORD const Year, WORD const Yea int scenario_time::julian_day() const { - int yy = static_cast(( m_time.wYear < 0 ? m_time.wYear + 1 : m_time.wYear ) - std::floor( ( 12 - m_time.wMonth ) / 10.f )); + int yy = static_cast( m_time.wYear - std::floor( ( 12 - m_time.wMonth ) / 10.f )); int mm = m_time.wMonth + 9; if( mm >= 12 ) { mm -= 12; } diff --git a/utilities/utilities.cpp b/utilities/utilities.cpp index 62f601bd..ebeae5b3 100644 --- a/utilities/utilities.cpp +++ b/utilities/utilities.cpp @@ -249,23 +249,18 @@ std::string to_string(int Value, int width) std::string to_string(double Value, int precision) { - std::ostringstream o; - o << std::fixed << std::setprecision(precision) << Value; - return std::move(o).str(); + return std::format("{:.{}f}", Value, precision); }; std::string to_string(double const Value, int const Precision, int const Width) { - std::ostringstream o; - o << std::setw(Width) << std::fixed << std::setprecision(Precision) << Value; - return std::move(o).str(); + return std::format("{:>{}.{}f}", Value, Width, Precision); }; std::string to_hex_str(int const Value, int const Width) { - std::ostringstream o; - o << "0x" << std::uppercase << std::setfill('0') << std::setw(Width) << std::hex << Value; - return o.str(); + // iostreams print negative values in hex as their unsigned representation + return std::format("0x{:0{}X}", static_cast(Value), Width); }; std::string const fractionlabels[] = {U8(" "), U8("¹"), U8("²"), U8("³"), U8("⁴"), U8("⁵"), U8("⁶"), U8("⁷"), U8("⁸"), U8("⁹")}; diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp index da61faf7..56378284 100644 --- a/vehicle/Train.cpp +++ b/vehicle/Train.cpp @@ -10033,8 +10033,6 @@ void TTrain::update_sounds(double const Deltatime) { dsbBuzzerShp->stop(); } - { - } if (m_distancecounterclear) {