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
This commit is contained in:
SamareshSingh
2025-11-13 17:44:43 -06:00
committed by GitHub
parent 88a0e07ad5
commit cdbd64e230

View File

@@ -160,8 +160,8 @@ protected:
payload = QString::fromUtf8(str.data(), static_cast<int>(str.size())); payload = QString::fromUtf8(str.data(), static_cast<int>(str.size()));
// convert color ranges from byte index to character index. // convert color ranges from byte index to character index.
if (msg.color_range_start < msg.color_range_end) { if (msg.color_range_start < msg.color_range_end) {
color_range_start = QString::fromUtf8(str.data(), msg.color_range_start).size(); color_range_start = QString::fromUtf8(str.data(), static_cast<qsizetype>(msg.color_range_start)).size();
color_range_end = QString::fromUtf8(str.data(), msg.color_range_end).size(); color_range_end = QString::fromUtf8(str.data(), static_cast<qsizetype>(msg.color_range_end)).size();
} }
} else { } else {
payload = QString::fromLatin1(str.data(), static_cast<int>(str.size())); payload = QString::fromLatin1(str.data(), static_cast<int>(str.size()));
@@ -171,7 +171,7 @@ protected:
qt_text_edit_, // text edit to append to qt_text_edit_, // text edit to append to
std::move(payload), // text to append std::move(payload), // text to append
default_color_, // default color default_color_, // default color
colors_.at(msg.level), // color to apply colors_.at(static_cast<size_t>(msg.level)), // color to apply
color_range_start, // color range start color_range_start, // color range start
color_range_end}; // color range end color_range_end}; // color range end