From c027d08c846bd6b9756f6c60ab616a56028f6bcd Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Tue, 21 Dec 2021 16:20:22 +0100 Subject: [PATCH] Increased warning level to #4 and fixed a number of warnings. --- MUtilities_VS2017.vcxproj | 9 ++++++--- MUtilities_VS2019.vcxproj | 7 ++++--- MUtilities_VS2022.vcxproj | 7 ++++--- include/MUtils/Hash.h | 2 +- include/MUtils/IPCChannel.h | 2 +- src/3rd_party/strnatcmp/src/strnatcmp.cpp | 6 +++--- src/ErrorHandler_Win32.cpp | 4 ++-- src/Global.cpp | 8 ++++---- src/OSSupport_Win32.cpp | 6 +++--- src/Registry_Win32.cpp | 4 ++-- src/Sound_Win32.cpp | 21 +++++++++++++-------- src/Terminal_Win32.cpp | 2 +- src/Translation.cpp | 2 +- 13 files changed, 45 insertions(+), 35 deletions(-) diff --git a/MUtilities_VS2017.vcxproj b/MUtilities_VS2017.vcxproj index edad498..f58dba7 100644 --- a/MUtilities_VS2017.vcxproj +++ b/MUtilities_VS2017.vcxproj @@ -162,7 +162,7 @@ NotUsing - Level3 + Level4 Disabled WIN32;MUTILS_DLL_EXPORT;_DEBUG;_LIB;QT_GUI_LIB;QT_CORE_LIB;QT_THREAD_SUPPORT;QT_DLL;QT_DEBUG;%(PreprocessorDefinitions) MultiThreadedDebugDLL @@ -172,6 +172,7 @@ Disabled Default ProgramDatabase + 4714;4324;4127 Windows @@ -182,7 +183,7 @@ - Level3 + Level4 NotUsing Full true @@ -202,6 +203,7 @@ false false true + 4714;4324;4127 Windows @@ -215,7 +217,7 @@ - Level3 + Level4 NotUsing Full true @@ -235,6 +237,7 @@ false false true + 4714;4324;4127 Windows diff --git a/MUtilities_VS2019.vcxproj b/MUtilities_VS2019.vcxproj index 0777dc9..a2e192e 100644 --- a/MUtilities_VS2019.vcxproj +++ b/MUtilities_VS2019.vcxproj @@ -159,7 +159,7 @@ NotUsing - Level3 + Level4 Disabled WIN32;MUTILS_DLL_EXPORT;_DEBUG;_LIB;QT_GUI_LIB;QT_CORE_LIB;QT_THREAD_SUPPORT;QT_DLL;QT_DEBUG;%(PreprocessorDefinitions) MultiThreadedDebugDLL @@ -179,7 +179,7 @@ - Level3 + Level4 NotUsing Full true @@ -212,7 +212,7 @@ - Level3 + Level4 NotUsing Full true @@ -232,6 +232,7 @@ false false true + 4714;4324;4127 Windows diff --git a/MUtilities_VS2022.vcxproj b/MUtilities_VS2022.vcxproj index 54123c6..207c499 100644 --- a/MUtilities_VS2022.vcxproj +++ b/MUtilities_VS2022.vcxproj @@ -159,7 +159,7 @@ NotUsing - Level3 + Level4 Disabled WIN32;MUTILS_DLL_EXPORT;_DEBUG;_LIB;QT_GUI_LIB;QT_CORE_LIB;QT_THREAD_SUPPORT;QT_DLL;QT_DEBUG;%(PreprocessorDefinitions) MultiThreadedDebugDLL @@ -179,7 +179,7 @@ - Level3 + Level4 NotUsing Full true @@ -212,7 +212,7 @@ - Level3 + Level4 NotUsing Full true @@ -232,6 +232,7 @@ false false true + 4714;4324;4127 Windows diff --git a/include/MUtils/Hash.h b/include/MUtils/Hash.h index ea0288c..2217f72 100644 --- a/include/MUtils/Hash.h +++ b/include/MUtils/Hash.h @@ -106,7 +106,7 @@ namespace MUtils QByteArray digest(const bool bAsHex = true) { return bAsHex ? finalize().toHex() : finalize(); } protected: - Hash(const char* key = NULL) {/*nothing to do*/}; + Hash(const char* /*key*/ = NULL) {/*nothing to do*/}; virtual bool process(const quint8 *const data, const quint32 len) = 0; virtual QByteArray finalize(void) = 0; diff --git a/include/MUtils/IPCChannel.h b/include/MUtils/IPCChannel.h index cbcdf26..580ee75 100644 --- a/include/MUtils/IPCChannel.h +++ b/include/MUtils/IPCChannel.h @@ -56,7 +56,7 @@ namespace MUtils bool read(quint32 &command, quint32 &flags, QStringList ¶ms); private: - IPCChannel(const IPCChannel&) : p(NULL), m_appVersionNo(-1) { throw "Constructor is disabled!"; } + IPCChannel(const IPCChannel&) : p(NULL), m_appVersionNo((unsigned int)(-1)) { throw "Constructor is disabled!"; } IPCChannel &operator=(const IPCChannel&) { throw "Assignment operator is disabled!"; return *this; } const QString m_applicationId; diff --git a/src/3rd_party/strnatcmp/src/strnatcmp.cpp b/src/3rd_party/strnatcmp/src/strnatcmp.cpp index 813a69f..74a2944 100644 --- a/src/3rd_party/strnatcmp/src/strnatcmp.cpp +++ b/src/3rd_party/strnatcmp/src/strnatcmp.cpp @@ -97,10 +97,10 @@ static int compare_right(nat_char const *a, nat_char const *b) return bias; } - return 0; + // return 0; } -static int compare_left(nat_char const *a,nat_char const *b) +static int compare_left(nat_char const *a, nat_char const *b) { /* Compare two left-aligned numbers: the first to have a different value wins. */ @@ -118,7 +118,7 @@ static int compare_left(nat_char const *a,nat_char const *b) return +1; } - return 0; + // return 0; } static int strnatcmp0(nat_char const *a, nat_char const *b, const bool fold_case) diff --git a/src/ErrorHandler_Win32.cpp b/src/ErrorHandler_Win32.cpp index 048fa48..ea973d7 100644 --- a/src/ErrorHandler_Win32.cpp +++ b/src/ErrorHandler_Win32.cpp @@ -35,7 +35,7 @@ /////////////////////////////////////////////////////////////////////////////// // Invalid parameters handler -static void my_invalid_param_handler(const wchar_t* exp, const wchar_t* fun, const wchar_t* fil, unsigned int, uintptr_t) +static void my_invalid_param_handler(const wchar_t* /*exp*/, const wchar_t* /*fun*/, const wchar_t* /*fil*/, unsigned int, uintptr_t) { MUtils::OS::fatal_exit(L"Invalid parameter handler invoked, application will exit!"); } @@ -48,7 +48,7 @@ static void my_signal_handler(int signal_num) } // Global exception handler -static LONG WINAPI my_exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo) +static LONG WINAPI my_exception_handler(struct _EXCEPTION_POINTERS* /*ExceptionInfo*/) { MUtils::OS::fatal_exit(L"Unhandeled exception handler invoked, application will exit!"); return LONG_MAX; diff --git a/src/Global.cpp b/src/Global.cpp index 54e4816..7a93a74 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -247,7 +247,7 @@ QString MUtils::make_temp_file(const QDir &basePath, const QString &extension, c QString MUtils::make_unique_file(const QString &basePath, const QString &baseName, const QString &extension, const bool fancy, const bool placeholder) { - return make_unique_file(QDir(basePath), baseName, extension, fancy); + return make_unique_file(QDir(basePath), baseName, extension, fancy, placeholder); } QString MUtils::make_unique_file(const QDir &basePath, const QString &baseName, const QString &extension, const bool fancy, const bool placeholder) @@ -282,10 +282,10 @@ QString MUtils::make_unique_file(const QDir &basePath, const QString &baseName, if (placeholder && (!fileName.isEmpty())) { - QFile placeholder(fileName); - if (placeholder.open(QIODevice::WriteOnly)) + QFile placeholderFile(fileName); + if (placeholderFile.open(QIODevice::WriteOnly)) { - placeholder.close(); + placeholderFile.close(); } } diff --git a/src/OSSupport_Win32.cpp b/src/OSSupport_Win32.cpp index df60224..8351641 100644 --- a/src/OSSupport_Win32.cpp +++ b/src/OSSupport_Win32.cpp @@ -180,7 +180,7 @@ typedef struct _progress_callback_data_t } progress_callback_data_t; -static DWORD __stdcall copy_file_progress(LARGE_INTEGER TotalFileSize, LARGE_INTEGER TotalBytesTransferred, LARGE_INTEGER StreamSize, LARGE_INTEGER StreamBytesTransferred, DWORD dwStreamNumber, DWORD dwCallbackReason, HANDLE hSourceFile, HANDLE hDestinationFile, LPVOID lpData) +static DWORD __stdcall copy_file_progress(LARGE_INTEGER TotalFileSize, LARGE_INTEGER TotalBytesTransferred, LARGE_INTEGER /*StreamSize*/, LARGE_INTEGER /*StreamBytesTransferred*/, DWORD /*dwStreamNumber*/, DWORD /*dwCallbackReason*/, HANDLE /*hSourceFile*/, HANDLE /*hDestinationFile*/, LPVOID lpData) { if(const progress_callback_data_t *data = (progress_callback_data_t*) lpData) { @@ -1439,7 +1439,7 @@ bool MUtils::OS::free_diskspace(const QString &path, quint64 &freeSpace) return true;; } - freeSpace = -1; + freeSpace = static_cast(-1); return false; } @@ -2012,7 +2012,7 @@ static volatile bool g_debug_check = check_debugger_helper(); static MUtils::Internal::CriticalSection g_fatal_exit_lock; static QAtomicInt g_fatal_exit_flag; -static BOOL CALLBACK fatal_exit_enum_helper(const HWND hwnd, const LPARAM lParam) +static BOOL CALLBACK fatal_exit_enum_helper(const HWND hwnd, const LPARAM /*lParam*/) { SetWindowPos(hwnd, HWND_NOTOPMOST, NULL, NULL, NULL, NULL, SWP_ASYNCWINDOWPOS | SWP_NOMOVE | SWP_NOSIZE); return TRUE; diff --git a/src/Registry_Win32.cpp b/src/Registry_Win32.cpp index 323d609..9dd6471 100644 --- a/src/Registry_Win32.cpp +++ b/src/Registry_Win32.cpp @@ -191,7 +191,7 @@ bool MUtils::Registry::RegistryKey::value_write(const QString &valueName, const bool MUtils::Registry::RegistryKey::value_read(const QString &valueName, quint32 &value) const { value = 0; - DWORD size = sizeof(quint32), type = -1; + DWORD size = sizeof(quint32), type = static_cast(-1); CHECK_STATUS(KEY_READ); return (RegQueryValueEx(p->m_hKey, valueName.isEmpty() ? NULL : MUTILS_WCHR(valueName), 0, &type, reinterpret_cast(&value), &size) == ERROR_SUCCESS) && (type == REG_DWORD); } @@ -199,7 +199,7 @@ bool MUtils::Registry::RegistryKey::value_read(const QString &valueName, quint32 bool MUtils::Registry::RegistryKey::value_read(const QString &valueName, QString &value) const { value = QString(); - wchar_t buffer[2048]; DWORD size = sizeof(wchar_t) * 2048, type = -1; + wchar_t buffer[2048]; DWORD size = sizeof(wchar_t) * 2048, type = static_cast(-1); CHECK_STATUS(KEY_READ); if((RegQueryValueEx(p->m_hKey, valueName.isEmpty() ? NULL : MUTILS_WCHR(valueName), 0, &type, reinterpret_cast(&(buffer[0])), &size) == ERROR_SUCCESS) && ((type == REG_SZ) || (type == REG_EXPAND_SZ))) { diff --git a/src/Sound_Win32.cpp b/src/Sound_Win32.cpp index 34ca5f9..ab54d2e 100644 --- a/src/Sound_Win32.cpp +++ b/src/Sound_Win32.cpp @@ -103,7 +103,7 @@ bool MUtils::Sound::play_sound(const QString &name, const bool &bAsync) { if(const unsigned char *data = get_sound_from_cache(name)) { - return PlaySound(LPCWSTR(data), NULL, (SND_MEMORY | (bAsync ? SND_ASYNC : SND_SYNC))) != FALSE; + return PlaySoundW(LPCWSTR(data), NULL, (SND_MEMORY | (bAsync ? SND_ASYNC : SND_SYNC))); } } @@ -112,7 +112,12 @@ bool MUtils::Sound::play_sound(const QString &name, const bool &bAsync) bool MUtils::Sound::play_system_sound(const QString &alias, const bool &bAsync) { - return PlaySound(MUTILS_WCHR(alias), GetModuleHandle(NULL), (SND_ALIAS | (bAsync ? SND_ASYNC : SND_SYNC))) != FALSE; + if (!alias.isEmpty()) + { + return PlaySoundW(MUTILS_WCHR(alias), NULL, (SND_ALIAS | (bAsync ? SND_ASYNC : SND_SYNC))); + } + + return false; } bool MUtils::Sound::play_sound_file(const QString &library, const unsigned short uiSoundIdx, const bool &bAsync) @@ -131,15 +136,15 @@ bool MUtils::Sound::play_sound_file(const QString &library, const unsigned short if(libraryFile.exists() && libraryFile.isFile()) { - if(const HMODULE module = GetModuleHandleW(MUTILS_WCHR(QDir::toNativeSeparators(libraryFile.canonicalFilePath())))) + if(const HMODULE module = LoadLibraryW(MUTILS_WCHR(QDir::toNativeSeparators(libraryFile.canonicalFilePath())))) { - result = (PlaySound(MAKEINTRESOURCE(uiSoundIdx), module, (SND_RESOURCE | (bAsync ? SND_ASYNC : SND_SYNC))) != FALSE); - } - else if(const HMODULE module = LoadLibraryW(MUTILS_WCHR(QDir::toNativeSeparators(libraryFile.canonicalFilePath())))) - { - result = (PlaySound(MAKEINTRESOURCE(uiSoundIdx), module, (SND_RESOURCE | (bAsync ? SND_ASYNC : SND_SYNC))) != FALSE); + result = PlaySoundW(MAKEINTRESOURCE(uiSoundIdx), module, (SND_RESOURCE | (bAsync ? SND_ASYNC : SND_SYNC))); FreeLibrary(module); } + else + { + qWarning("PlaySound: File \"%s\" failed to load!", MUTILS_UTF8(libraryFile.absoluteFilePath())); + } } else { diff --git a/src/Terminal_Win32.cpp b/src/Terminal_Win32.cpp index cd6d698..bdc5e60 100644 --- a/src/Terminal_Win32.cpp +++ b/src/Terminal_Win32.cpp @@ -203,7 +203,7 @@ void MUtils::Terminal::setup(int &argc, char **argv, const char* const appName, g_terminal_log_file.reset(new QFile(MUTILS_QSTR(logfile))); if(g_terminal_log_file->open(QIODevice::WriteOnly)) { - static const char MARKER[3] = { char(0xEF), char(0xBB), char(0xBF) }; + static const char MARKER[3] = { '\xEF', '\xBB', '\xBF' }; g_terminal_log_file->write(MARKER, 3); } free(logfile); diff --git a/src/Translation.cpp b/src/Translation.cpp index 5bd41b1..c15b46a 100644 --- a/src/Translation.cpp +++ b/src/Translation.cpp @@ -106,7 +106,7 @@ int MUtils::Translation::enumerate(QStringList &list) return -1; } - list.swap(g_translation_data->keys()); + list = g_translation_data->keys(); return list.count(); }