fix some memory safety things (thanks ASan)

This commit is contained in:
ouwou
2021-03-10 03:33:39 -05:00
parent 1538e56052
commit 35473b3baf
3 changed files with 8 additions and 5 deletions

View File

@@ -714,8 +714,6 @@ void ChatMessageItemContainer::HandleEmojis(Gtk::TextView &tv) {
void ChatMessageItemContainer::CleanupEmojis(Glib::RefPtr<Gtk::TextBuffer> buf) {
static auto rgx = Glib::Regex::create(R"(<a?:([\w\d_]+):(\d+)>)");
auto &img = Abaddon::Get().GetImageManager();
auto text = GetText(buf);
Glib::MatchInfo match;
@@ -724,6 +722,8 @@ void ChatMessageItemContainer::CleanupEmojis(Glib::RefPtr<Gtk::TextBuffer> buf)
int mstart, mend;
if (!match.fetch_pos(0, mstart, mend)) break;
const auto new_term = ":" + match.fetch(1) + ":";
const auto chars_start = g_utf8_pointer_to_offset(text.c_str(), text.c_str() + mstart);
const auto chars_end = g_utf8_pointer_to_offset(text.c_str(), text.c_str() + mend);
auto start_it = buf->get_iter_at_offset(chars_start);
@@ -736,7 +736,7 @@ void ChatMessageItemContainer::CleanupEmojis(Glib::RefPtr<Gtk::TextBuffer> buf)
const int blen = text.size();
startpos -= (alen - blen);
buf->insert(it, ":" + match.fetch(1) + ":");
buf->insert(it, new_term);
text = GetText(buf);
}