From cdbd64e2305a712ec9a360e5a1e05aa1dcab85e7 Mon Sep 17 00:00:00 2001 From: SamareshSingh <97642706+ssam18@users.noreply.github.com> Date: Thu, 13 Nov 2025 17:44:43 -0600 Subject: [PATCH] Fix sign conversion warnings in qt_sinks.h (#3487) Add static_cast to fix compiler warnings when building with -Werror=sign-conversion and -Werror=shorten-64-to-32: 1. Cast msg.color_range_start/end to qsizetype when passing to QString::fromUtf8(), since QString expects signed qsizetype but the message fields are size_t (unsigned). 2. Cast msg.level to size_t when indexing into colors_ array, since level_enum is a signed int but array indexing expects size_t. These casts are safe because: - qsizetype is guaranteed to be the same size as size_t per Qt docs - color_range values come from valid string positions - level values are from a small enum range Fixes #3321 --- include/spdlog/sinks/qt_sinks.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/spdlog/sinks/qt_sinks.h b/include/spdlog/sinks/qt_sinks.h index d319e847..60982eb1 100644 --- a/include/spdlog/sinks/qt_sinks.h +++ b/include/spdlog/sinks/qt_sinks.h @@ -160,8 +160,8 @@ protected: payload = QString::fromUtf8(str.data(), static_cast(str.size())); // convert color ranges from byte index to character index. if (msg.color_range_start < msg.color_range_end) { - color_range_start = QString::fromUtf8(str.data(), msg.color_range_start).size(); - color_range_end = QString::fromUtf8(str.data(), msg.color_range_end).size(); + color_range_start = QString::fromUtf8(str.data(), static_cast(msg.color_range_start)).size(); + color_range_end = QString::fromUtf8(str.data(), static_cast(msg.color_range_end)).size(); } } else { payload = QString::fromLatin1(str.data(), static_cast(str.size())); @@ -171,7 +171,7 @@ protected: qt_text_edit_, // text edit to append to std::move(payload), // text to append default_color_, // default color - colors_.at(msg.level), // color to apply + colors_.at(static_cast(msg.level)), // color to apply color_range_start, // color range start color_range_end}; // color range end