Fix iterator-use-after-invalidation in tooltips

It's undefined behavior to access an iterator after calling std::map::erase(),
the correct method is to use the new iterator that erase() returns instead.

(cherry picked from commit b0c59a558a)
This commit is contained in:
Steve Cotton 2021-11-05 09:25:50 +01:00 committed by Steve Cotton
parent e4497ba160
commit a9e534812d

View file

@ -132,7 +132,7 @@ void clear_tooltips(const SDL_Rect& rect)
if (i==current_tooltip) {
clear_tooltip();
}
tips.erase(i++);
i = tips.erase(i);
current_tooltip = tips.end();
} else {
++i;
@ -175,13 +175,7 @@ void remove_tooltip(int id)
int add_tooltip(const SDL_Rect& rect, const std::string& message, const std::string& action, bool use_markup, const surface& foreground)
{
for(std::map<int, tooltip>::iterator it = tips.begin(); it != tips.end();) {
if(sdl::rects_overlap(it->second.rect,rect)) {
tips.erase(it++);
} else {
++it;
}
}
clear_tooltips(rect);
int id = tooltip_id++;