diff --git a/grepWinNP3/sktoolslib_mod/SimpleIni.h b/grepWinNP3/sktoolslib_mod/SimpleIni.h index c7240da24..60bb784f3 100644 --- a/grepWinNP3/sktoolslib_mod/SimpleIni.h +++ b/grepWinNP3/sktoolslib_mod/SimpleIni.h @@ -214,6 +214,11 @@ # pragma warning (disable: 4127 4503 4702 4786) #endif +// workaround for invalid (false positive) assertion SI_ASSERT(hFile != INVALID_HANDLE_VALUE) +#ifndef _WIN64 +# undef INVALID_HANDLE_VALUE +# define INVALID_HANDLE_VALUE ((HANDLE)INTPTR_MAX) +#endif // Defines the conversion classes for different libraries. Before including // SimpleIni.h, set the converter that you wish you use by defining one of the @@ -306,6 +311,10 @@ enum class SI_Error : int { # define SI_WCHAR_T UChar #endif +#ifndef IS_VALID_HANDLE +#define IS_VALID_HANDLE(HNDL) ((HNDL) && ((HNDL) != INVALID_HANDLE_VALUE)) +#endif + // --------------------------------------------------------------------------- // MAIN TEMPLATE CLASS // --------------------------------------------------------------------------- @@ -1435,22 +1444,22 @@ CSimpleIniTempl::LoadFile( ) { if (a_pwszFile && a_pwszFile[0]) -{ - HANDLE hFile = CreateFile(a_pwszFile, - GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, - nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); + { + HANDLE hFile = CreateFile(a_pwszFile, + GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, + nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); SI_ASSERT(hFile != INVALID_HANDLE_VALUE); - if (hFile == INVALID_HANDLE_VALUE) { - return SI_Error::SI_FILE; + if (!IS_VALID_HANDLE(hFile)) { + return SI_Error::SI_FILE; + } + + SI_Error rc = LoadFile(hFile); + + CloseHandle(hFile); + return rc; } - - SI_Error rc = LoadFile(hFile); - - CloseHandle(hFile); - return rc; -} return SI_Error::SI_FILE; } @@ -2641,22 +2650,22 @@ CSimpleIniTempl::SaveFile( ) const { if (a_pwszFile && a_pwszFile[0]) -{ - HANDLE hFile = CreateFile(a_pwszFile, - GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, - nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + { + HANDLE hFile = CreateFile(a_pwszFile, + GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, + nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); SI_ASSERT(hFile != INVALID_HANDLE_VALUE); - if (hFile == INVALID_HANDLE_VALUE) { - return SI_Error::SI_FILE; + if (!IS_VALID_HANDLE(hFile)) { + return SI_Error::SI_FILE; + } + + SI_Error rc = SaveFile(hFile, a_bAddSignature); + + CloseHandle(hFile); + return rc; } - - SI_Error rc = SaveFile(hFile, a_bAddSignature); - - CloseHandle(hFile); - return rc; -} return SI_Error::SI_FILE; } diff --git a/src/Config/SimpleIni.h b/src/Config/SimpleIni.h index 8d09a865a..96ad5eae1 100644 --- a/src/Config/SimpleIni.h +++ b/src/Config/SimpleIni.h @@ -214,6 +214,11 @@ # pragma warning (disable: 4127 4503 4702 4786) #endif +// workaround for invalid (false positive) assertion SI_ASSERT(hFile != INVALID_HANDLE_VALUE) +#ifndef _WIN64 +# undef INVALID_HANDLE_VALUE +# define INVALID_HANDLE_VALUE ((HANDLE)INTPTR_MAX) +#endif // Defines the conversion classes for different libraries. Before including // SimpleIni.h, set the converter that you wish you use by defining one of the @@ -300,14 +305,14 @@ enum class SI_Error : int { #if defined(_WIN32) # define SI_HAS_WIDE_FILE # define SI_USE_LOCKING_WIDE_FILE -# define SI_WCHAR_T wchar_t +# define SI_WCHAR_T wchar_t #elif defined(SI_CONVERT_ICU) # define SI_HAS_WIDE_FILE # define SI_WCHAR_T UChar #endif #ifndef IS_VALID_HANDLE -#define IS_VALID_HANDLE(HNDL) (((HNDL) && ((HNDL) != INVALID_HANDLE_VALUE)) ? true : false) +#define IS_VALID_HANDLE(HNDL) ((HNDL) && ((HNDL) != INVALID_HANDLE_VALUE)) #endif // ---------------------------------------------------------------------------