From 190b030035d2030d52d0a6ad1a5846f606c1897b Mon Sep 17 00:00:00 2001 From: Stefan Uhrig Date: Wed, 12 Oct 2022 16:38:46 +0200 Subject: [PATCH] Fix some unreachable code and possible loss of data warnings --- src/odbc/Config.h | 10 +++++++++- src/odbc/StringConverter.cpp | 2 +- src/odbc/internal/charset/Utf8.h | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/odbc/Config.h b/src/odbc/Config.h index 374c2b6..994e5c4 100644 --- a/src/odbc/Config.h +++ b/src/odbc/Config.h @@ -23,7 +23,15 @@ # endif #endif //------------------------------------------------------------------------------ -#ifdef _WIN32 +#if defined(__clang__) || defined(__GNUC__) +# define ODBC_UNREACHABLE __builtin_unreachable() +#elif defined(_MSC_VER) +# define ODBC_UNREACHABLE __assume(false) +#else +# define ODBC_UNREACHABLE ((void)0) +#endif +//------------------------------------------------------------------------------ +#ifdef _MSC_VER # pragma warning(disable: 4251 4275) #endif //------------------------------------------------------------------------------ diff --git a/src/odbc/StringConverter.cpp b/src/odbc/StringConverter.cpp index fda92d6..a813e70 100644 --- a/src/odbc/StringConverter.cpp +++ b/src/odbc/StringConverter.cpp @@ -53,7 +53,7 @@ u16string StringConverter::utf8ToUtf16(const char* begin, const char* end) } else { - str.push_back(cp.second); + str.push_back(static_cast(cp.second)); } } diff --git a/src/odbc/internal/charset/Utf8.h b/src/odbc/internal/charset/Utf8.h index ce7f1db..22b0000 100644 --- a/src/odbc/internal/charset/Utf8.h +++ b/src/odbc/internal/charset/Utf8.h @@ -52,7 +52,7 @@ inline bool isValidSequence(int len, const char* c) return ((c[0] & 0xF8) == 0xF0) && ((c[1] & 0xC0) == 0x80) && ((c[2] & 0xC0) == 0x80) && ((c[3] & 0xC0) == 0x80); } - assert(false); + ODBC_UNREACHABLE; } //------------------------------------------------------------------------------ /** @@ -121,7 +121,7 @@ inline char32_t decode(int len, const char* c) case 4: return decode4(c); } - assert(false); + ODBC_UNREACHABLE; } //------------------------------------------------------------------------------ } // namespace utf8