From 977a190646785d50ab41b5a171a58aa3fb48bf07 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 23 Jan 2023 19:24:52 -0600 Subject: [PATCH] fix: msvc warnings (#4651) * fix: C4189 local variable is initialized but not referenced * fix: C4706 assignment within conditional expression * fix: C4018 signed/unsigned mismatch * fix: warning C4996 High-DPI scaling is always enabled. * fix: C4996: QApplication::fontMetrics() is deprecated https://github.com/qt/qtbase/commit/eed5514eaf03c04f1b93d0899789841b8488d9a6 --- libtransmission/net.cc | 2 +- qt/Application.cc | 5 +---- qt/FileTreeDelegate.cc | 2 +- tests/libtransmission/announcer-udp-test.cc | 2 +- utils/remote.cc | 23 +++++++-------------- 5 files changed, 12 insertions(+), 22 deletions(-) diff --git a/libtransmission/net.cc b/libtransmission/net.cc index 08ffcd26a..7d64443ac 100644 --- a/libtransmission/net.cc +++ b/libtransmission/net.cc @@ -50,7 +50,7 @@ std::string tr_net_strerror(int err) #ifdef _WIN32 auto buf = std::array{}; - auto const len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, err, 0, std::data(buf), std::size(buf), nullptr); + (void)FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, err, 0, std::data(buf), std::size(buf), nullptr); return std::string{ tr_strvStrip(std::data(buf)) }; #else diff --git a/qt/Application.cc b/qt/Application.cc index e7ca27555..3ef1968f0 100644 --- a/qt/Application.cc +++ b/qt/Application.cc @@ -370,7 +370,7 @@ Application::Application(int& argc, char** argv) void Application::loadTranslations() { - QStringList const qt_qm_dirs = QStringList() << QLibraryInfo::location(QLibraryInfo::TranslationsPath) << + auto const qt_qm_dirs = QStringList() << QLibraryInfo::location(QLibraryInfo::TranslationsPath) << #ifdef TRANSLATIONS_DIR QStringLiteral(TRANSLATIONS_DIR) << #endif @@ -664,9 +664,6 @@ int tr_main(int argc, char** argv) { InteropHelper::initialize(); - Application::setAttribute(Qt::AA_EnableHighDpiScaling); - Application::setAttribute(Qt::AA_UseHighDpiPixmaps); - Application const app(argc, argv); return QApplication::exec(); } diff --git a/qt/FileTreeDelegate.cc b/qt/FileTreeDelegate.cc index 221d85d2e..0e3c3e52c 100644 --- a/qt/FileTreeDelegate.cc +++ b/qt/FileTreeDelegate.cc @@ -52,7 +52,7 @@ void FileTreeDelegate::paint(QPainter* painter, QStyleOptionViewItem const& opti p.rect = option.rect; p.rect.setSize(QSize(option.rect.width() - 4, option.rect.height() - 8)); p.rect.moveCenter(option.rect.center()); - p.fontMetrics = QApplication::fontMetrics(); + p.fontMetrics = QFontMetrics{ QApplication::font() }; p.minimum = 0; p.maximum = 100; p.textAlignment = Qt::AlignCenter; diff --git a/tests/libtransmission/announcer-udp-test.cc b/tests/libtransmission/announcer-udp-test.cc index 3d032eae1..f2513180c 100644 --- a/tests/libtransmission/announcer-udp-test.cc +++ b/tests/libtransmission/announcer-udp-test.cc @@ -409,7 +409,7 @@ TEST_F(AnnouncerUdpTest, canMultiScrape) auto buf = libtransmission::Buffer{}; buf.addUint32(ScrapeAction); buf.addUint32(scrape_transaction_id); - for (size_t i = 0; i < expected_response.row_count; ++i) + for (int i = 0; i < expected_response.row_count; ++i) { buf.addUint32(expected_response.rows[i].seeders); buf.addUint32(expected_response.rows[i].downloads); diff --git a/utils/remote.cc b/utils/remote.cc index d8fbb5dfe..74c81d1d5 100644 --- a/utils/remote.cc +++ b/utils/remote.cc @@ -950,13 +950,11 @@ static void printDetails(tr_variant* top) { fmt::print(" Labels: "); - size_t child_pos = 0; - tr_variant const* child; - while ((child = tr_variantListChild(l, child_pos++))) + for (size_t child_idx = 0, n_children = tr_variantListSize(l); child_idx < n_children; ++child_idx) { - if (tr_variantGetStrView(child, &sv)) + if (tr_variantGetStrView(tr_variantListChild(l, child_idx++), &sv)) { - fmt::print(child_pos == 1 ? "{:s}" : ", {:s}", sv); + fmt::print(child_idx == 1 ? "{:s}" : ", {:s}", sv); } } @@ -2039,18 +2037,13 @@ static void filterIds(tr_variant* top, Config& config) case 'l': // label if (tr_variant * l; tr_variantDictFindList(d, TR_KEY_labels, &l)) { - size_t child_pos = 0; - tr_variant const* child; - std::string_view sv; - while ((child = tr_variantListChild(l, child_pos++))) + for (size_t child_idx = 0, n_children = tr_variantListSize(l); child_idx < n_children; ++child_idx) { - if (tr_variantGetStrView(child, &sv)) + if (auto sv = std::string_view{}; + tr_variantGetStrView(tr_variantListChild(l, child_idx), &sv) && arg == sv) { - if (arg == sv) - { - include = !include; - break; - } + include = !include; + break; } } }