2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Fix crash in case of incorrect Text entities.

This commit is contained in:
John Preston
2018-01-18 14:04:25 +03:00
parent 7814ee0f7a
commit f88cbf3d4b
4 changed files with 65 additions and 15 deletions

View File

@@ -493,6 +493,31 @@ void SetAnnotation(const std::string &key, const QString &value) {
}
}
void SetAnnotationHex(const std::string &key, const QString &value) {
if (value.isEmpty()) {
return SetAnnotation(key, value);
}
const auto utf = value.toUtf8();
auto buffer = std::string();
buffer.reserve(4 * utf.size());
const auto hexDigit = [](std::uint8_t value) {
if (value >= 10) {
return 'A' + (value - 10);
}
return '0' + value;
};
const auto appendHex = [&](std::uint8_t value) {
buffer.push_back('\\');
buffer.push_back('x');
buffer.push_back(hexDigit(value / 16));
buffer.push_back(hexDigit(value % 16));
};
for (const auto ch : utf) {
appendHex(ch);
}
ProcessAnnotations[key] = std::move(buffer);
}
void SetAnnotationRef(const std::string &key, const QString *valuePtr) {
if (valuePtr) {
ProcessAnnotationRefs[key] = valuePtr;