diff --git a/src/lib/icu/Collate.cxx b/src/lib/icu/Collate.cxx index aa5df4e47..b6fc9e136 100644 --- a/src/lib/icu/Collate.cxx +++ b/src/lib/icu/Collate.cxx @@ -99,13 +99,16 @@ IcuCollate(const char *a, const char *b) #else /* fall back to ucol_strcoll() */ - const auto au = UCharFromUTF8(a); - const auto bu = UCharFromUTF8(b); + try { + const auto au = UCharFromUTF8(a); + const auto bu = UCharFromUTF8(b); - return !au.IsNull() && !bu.IsNull() - ? (int)ucol_strcoll(collator, au.begin(), au.size(), - bu.begin(), bu.size()) - : strcasecmp(a, b); + return ucol_strcoll(collator, au.begin(), au.size(), + bu.begin(), bu.size()); + } catch (const std::runtime_error &) { + /* fall back to plain strcasecmp() */ + return strcasecmp(a, b); + } #endif #elif defined(WIN32) diff --git a/src/lib/icu/Converter.cxx b/src/lib/icu/Converter.cxx index 7d1a45382..815697821 100644 --- a/src/lib/icu/Converter.cxx +++ b/src/lib/icu/Converter.cxx @@ -129,7 +129,7 @@ try { AllocatedString IcuConverter::FromUTF8(const char *s) const -{ +try { #ifdef HAVE_ICU const ScopeLock protect(mutex); @@ -156,6 +156,8 @@ IcuConverter::FromUTF8(const char *s) const #elif defined(HAVE_ICONV) return DoConvert(from_utf8, s); #endif +} catch (const std::runtime_error &) { + return nullptr; } #endif diff --git a/src/lib/icu/Util.cxx b/src/lib/icu/Util.cxx index 9a8c44b9c..9342001f2 100644 --- a/src/lib/icu/Util.cxx +++ b/src/lib/icu/Util.cxx @@ -47,7 +47,7 @@ UCharFromUTF8(const char *src) src, src_length, &error_code); if (U_FAILURE(error_code)) - return {}; + throw std::runtime_error(u_errorName(error_code)); dest.SetSize(dest_length); return dest; diff --git a/src/lib/icu/Util.hxx b/src/lib/icu/Util.hxx index bae694bc6..863f32c22 100644 --- a/src/lib/icu/Util.hxx +++ b/src/lib/icu/Util.hxx @@ -30,6 +30,8 @@ template class AllocatedString; /** * Wrapper for u_strFromUTF8(). + * + * Throws std::runtime_error on error. */ AllocatedArray UCharFromUTF8(const char *src);