From 1f6da4c7346cfad264411552dcfb1f2a9740f0f9 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 1 Apr 2016 11:43:14 +0400 Subject: [PATCH] Logging crashed string in hexdump ofutf8. --- Telegram/SourceFiles/logs.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/logs.cpp b/Telegram/SourceFiles/logs.cpp index 668990da2c..0040b4f1b1 100644 --- a/Telegram/SourceFiles/logs.cpp +++ b/Telegram/SourceFiles/logs.cpp @@ -768,9 +768,24 @@ namespace internal { if (!ReportingHeaderWritten) { ReportingHeaderWritten = true; + auto dec2hex = [](int value) -> char { + if (value >= 0 && value < 10) { + return '0' + value; + } else if (value >= 10 && value < 16) { + return 'a' + (value - 10); + } + return '#'; + }; for (const auto &i : ProcessAnnotationRefs) { - ProcessAnnotations[i.first] = i.second->toUtf8().constData(); + QByteArray utf8 = i.second->toUtf8(); + std::string wrapped; + wrapped.reserve(4 * utf8.size()); + for (auto ch : utf8) { + auto uch = static_cast(ch); + wrapped.append("\\x", 2).append(1, dec2hex(uch >> 4)).append(1, dec2hex(uch & 0x0F)); + } + ProcessAnnotations[i.first] = wrapped; } const Annotations c_ProcessAnnotations(ProcessAnnotations);