From eacecddfb03922985e0c63a2645186c4b9b26389 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 18 Feb 2026 20:02:12 -0800 Subject: [PATCH] Fix real bugs found by clang-tidy - game_handler.cpp: use-after-move on node.id after std::move(node) (save nodeId before the move) - tcp_socket.cpp, world_socket.cpp: virtual call in destructor bypasses dispatch; use qualified TCPSocket::disconnect() / WorldSocket::disconnect() to make intent explicit - wmo_renderer.cpp: float loop counters risk precision drift; replace with integer step counts and reconstruct float from index - game_screen.cpp: (float + 0.5) cast to int is incorrect rounding; use std::lround instead --- src/game/game_handler.cpp | 7 ++++--- src/network/tcp_socket.cpp | 2 +- src/network/world_socket.cpp | 2 +- src/rendering/wmo_renderer.cpp | 8 ++++++-- src/ui/game_screen.cpp | 2 +- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/game/game_handler.cpp b/src/game/game_handler.cpp index 0e993f42..6cde0b74 100644 --- a/src/game/game_handler.cpp +++ b/src/game/game_handler.cpp @@ -9513,10 +9513,11 @@ void GameHandler::loadTaxiDbc() { node.mountDisplayIdHorde = nodesDbc->getUInt32(i, mountHordeFB); } } - if (node.id > 0) { - taxiNodes_[node.id] = std::move(node); + uint32_t nodeId = node.id; + if (nodeId > 0) { + taxiNodes_[nodeId] = std::move(node); } - if (node.id == 195) { + if (nodeId == 195) { std::string fields; for (uint32_t f = 0; f < fieldCount; f++) { fields += std::to_string(f) + ":" + std::to_string(nodesDbc->getUInt32(i, f)) + " "; diff --git a/src/network/tcp_socket.cpp b/src/network/tcp_socket.cpp index af03faa4..a83ef190 100644 --- a/src/network/tcp_socket.cpp +++ b/src/network/tcp_socket.cpp @@ -11,7 +11,7 @@ TCPSocket::TCPSocket() { } TCPSocket::~TCPSocket() { - disconnect(); + TCPSocket::disconnect(); // qualified call: virtual dispatch is bypassed in destructors } bool TCPSocket::connect(const std::string& host, uint16_t port) { diff --git a/src/network/world_socket.cpp b/src/network/world_socket.cpp index 996d6f07..3ada8c3e 100644 --- a/src/network/world_socket.cpp +++ b/src/network/world_socket.cpp @@ -60,7 +60,7 @@ WorldSocket::WorldSocket() { } WorldSocket::~WorldSocket() { - disconnect(); + WorldSocket::disconnect(); // qualified call: virtual dispatch is bypassed in destructors } bool WorldSocket::connect(const std::string& host, uint16_t port) { diff --git a/src/rendering/wmo_renderer.cpp b/src/rendering/wmo_renderer.cpp index 51a23305..f9b6ae9d 100644 --- a/src/rendering/wmo_renderer.cpp +++ b/src/rendering/wmo_renderer.cpp @@ -890,8 +890,12 @@ void WMORenderer::precomputeFloorCache() { float startX = std::floor(boundsMin.x / FLOOR_GRID_CELL_SIZE) * FLOOR_GRID_CELL_SIZE; float startY = std::floor(boundsMin.y / FLOOR_GRID_CELL_SIZE) * FLOOR_GRID_CELL_SIZE; - for (float x = startX; x <= boundsMax.x; x += FLOOR_GRID_CELL_SIZE) { - for (float y = startY; y <= boundsMax.y; y += FLOOR_GRID_CELL_SIZE) { + int stepsX = static_cast((boundsMax.x - startX) / FLOOR_GRID_CELL_SIZE) + 1; + int stepsY = static_cast((boundsMax.y - startY) / FLOOR_GRID_CELL_SIZE) + 1; + for (int ix = 0; ix < stepsX; ++ix) { + float x = startX + ix * FLOOR_GRID_CELL_SIZE; + for (int iy = 0; iy < stepsY; ++iy) { + float y = startY + iy * FLOOR_GRID_CELL_SIZE; // Sample at grid cell center float sampleX = x + FLOOR_GRID_CELL_SIZE * 0.5f; float sampleY = y + FLOOR_GRID_CELL_SIZE * 0.5f; diff --git a/src/ui/game_screen.cpp b/src/ui/game_screen.cpp index 4fdf7658..6a5a0bf2 100644 --- a/src/ui/game_screen.cpp +++ b/src/ui/game_screen.cpp @@ -5462,7 +5462,7 @@ void GameScreen::renderSettingsWindow() { break; } } - pendingUiOpacity = static_cast(uiOpacity_ * 100.0f + 0.5f); + pendingUiOpacity = static_cast(std::lround(uiOpacity_ * 100.0f)); pendingMinimapRotate = minimapRotate_; pendingMinimapSquare = minimapSquare_; if (renderer) {