Merge pull request #7586 from heinrich5991/pr_ddnet_invalid_utf16_error

Make error message about invalid UTF-16 more precise
This commit is contained in:
Robert Müller 2023-12-04 08:56:35 +00:00 committed by GitHub
commit 9e3d7c47fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View file

@ -182,7 +182,7 @@ bool dbg_assert_has_failed()
return dbg_assert_failing.load(std::memory_order_acquire);
}
void dbg_assert_imp(const char *filename, int line, int test, const char *msg)
void dbg_assert_imp(const char *filename, int line, bool test, const char *msg)
{
if(!test)
{
@ -1461,7 +1461,7 @@ std::string windows_format_system_message(unsigned long error)
std::optional<std::string> message = windows_wide_to_utf8(wide_message);
LocalFree(wide_message);
return message.value_or("invalid error");
return message.value_or("(invalid UTF-16 in error message)");
}
#endif
@ -4430,7 +4430,8 @@ void os_locale_str(char *locale, size_t length)
dbg_assert(GetUserDefaultLocaleName(wide_buffer, std::size(wide_buffer)) > 0, "GetUserDefaultLocaleName failure");
const std::optional<std::string> buffer = windows_wide_to_utf8(wide_buffer);
str_copy(locale, buffer.value_or("en-US").c_str(), length);
dbg_assert(buffer.has_value(), "GetUserDefaultLocaleName returned invalid UTF-16");
str_copy(locale, buffer.value().c_str(), length);
#elif defined(CONF_PLATFORM_MACOS)
CFLocaleRef locale_ref = CFLocaleCopyCurrent();
CFStringRef locale_identifier_ref = static_cast<CFStringRef>(CFLocaleGetValue(locale_ref, kCFLocaleIdentifier));

View file

@ -73,7 +73,7 @@
* @see dbg_break
*/
#define dbg_assert(test, msg) dbg_assert_imp(__FILE__, __LINE__, test, msg)
void dbg_assert_imp(const char *filename, int line, int test, const char *msg);
void dbg_assert_imp(const char *filename, int line, bool test, const char *msg);
#ifdef __clang_analyzer__
#include <cassert>