From 59e37210f354f981f80da45898d345b2ae73cb30 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 27 Apr 2022 23:44:16 +0800 Subject: [PATCH 1/3] Use correct type for comparisons `_write()` actually returns `int` type. And fix wrong function parameters. Closes #16938. Closes #16944. --- src/app/main.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/app/main.cpp b/src/app/main.cpp index 7f02ec67b..cd670dcbf 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #if defined(Q_OS_UNIX) #include @@ -318,17 +319,13 @@ int main(int argc, char *argv[]) void reportToUser(const char *str) { const size_t strLen = strlen(str); -#ifndef Q_OS_WIN - if (write(STDERR_FILENO, str, strLen) < static_cast(strLen)) - { - const auto dummy = write(STDOUT_FILENO, str, strLen); +#ifdef Q_OS_WIN + if (_write(_fileno(stderr), str, strLen) < static_cast(strLen)) + std::ignore = _write(_fileno(stdout), str, strLen); #else - if (_write(STDERR_FILENO, str, strLen) < static_cast(strLen)) - { - const auto dummy = _write(STDOUT_FILENO, str, strLen); + if (write(STDERR_FILENO, str, strLen) < static_cast(strLen)) + std::ignore = write(STDOUT_FILENO, str, strLen); #endif - Q_UNUSED(dummy); - } } #endif From c5cbda0bbe287829d33b6d69446ffa6b66e9e595 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 27 Apr 2022 23:56:06 +0800 Subject: [PATCH 2/3] Avoid splitting code over `ifdef` boundary By removing unimportant debug message. --- src/app/main.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/app/main.cpp b/src/app/main.cpp index cd670dcbf..e3241bbb9 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -211,9 +211,7 @@ int main(int argc, char *argv[]) throw CommandLineParameterError(QObject::tr("You cannot use %1: qBittorrent is already running for this user.") .arg(u"-d (or --daemon)"_qs)); } - else #endif - qDebug("qBittorrent is already running for this user."); QThread::msleep(300); app->sendParams(params.paramList()); From 639ed40314c18342aeeac854f4b26e55c54375cd Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 28 Apr 2022 18:40:15 +0800 Subject: [PATCH 3/3] Disable Linux-specific function when compiling for Windows --- src/app/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app/main.cpp b/src/app/main.cpp index e3241bbb9..5ab06e28b 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -352,8 +352,10 @@ void sigAbnormalHandler(int signum) reportToUser(msg); reportToUser(sigName); reportToUser("\n"); +#if !defined Q_OS_WIN print_stacktrace(); // unsafe #endif +#endif #if defined Q_OS_WIN && !defined DISABLE_GUI StacktraceDialog dlg; // unsafe