From d9a83010855582f5e5287a056e9ead6a1f908c8d Mon Sep 17 00:00:00 2001 From: nguyenphivn Date: Sat, 12 Sep 2026 15:37:23 +0700 Subject: [PATCH] fix(monitor): clamp the mouse-socket log length so the build is warning-free Building dev with GCC 16 emits one warning, and this is it: char_traits.h:432:56: warning: '__builtin_memcpy' accessing between 9223372036854775760 and 9223372036854775806 bytes ... [-Wrestrict] inlined from 'void mousePressResetThread()' at src/lotus-monitor.cpp:113 Not a real out-of-bounds read: n comes from recv() into a 16-byte buffer and the n <= 0 case has already returned, so n is in [1, sizeof(buf)] at that point. GCC cannot prove the upper bound, so it assumes the ssize_t could reach size_t range. Clamping the length makes the bound explicit and the build clean. Worth doing because it was the only warning left: one that always shows is one that trains you to skim past the next warning, which may be real. ctest 9/9. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01TvNe693ge85eB4QPs6hpjV --- src/lotus-monitor.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lotus-monitor.cpp b/src/lotus-monitor.cpp index 884f3a26..8d908d0a 100644 --- a/src/lotus-monitor.cpp +++ b/src/lotus-monitor.cpp @@ -8,6 +8,7 @@ #include "lotus-monitor.h" #include "lotus-utils.h" +#include #include #include #include @@ -110,7 +111,10 @@ void mousePressResetThread() { needEngineReset.store(true, std::memory_order_release); g_mouse_clicked.store(true, std::memory_order_release); } else { - LOTUS_WARN("Unexpected message received from mouse socket: " + std::string(buf, n)); + // Clamp for the compiler's benefit: n is already known to be in [1, sizeof(buf)] + // here, but GCC cannot prove it and warns that the length may be a huge size_t. + const size_t len = std::min(static_cast(n), sizeof(buf)); + LOTUS_WARN("Unexpected message received from mouse socket: " + std::string(buf, len)); } } else if (ret < 0 && errno != EINTR) {