Changeset - r27878:15d820d4fa04
[Not reviewed]
master
0 1 0
Peter Nelson - 8 months ago 2023-09-09 15:38:12
peter1138@openttd.org
Codechange: Don't allocate a text effect with INVALID_TE_ID.

Previously, despite INVALID_TE_ID existing, it was not checked during allocation and there was no limit to the number of text effects.
1 file changed with 5 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/texteff.cpp
Show inline comments
 
@@ -43,7 +43,11 @@ TextEffectID AddTextEffect(StringID msg,
 
	if (_game_mode == GM_MENU) return INVALID_TE_ID;
 

	
 
	auto it = std::find_if(std::begin(_text_effects), std::end(_text_effects), [](const TextEffect &te) { return te.string_id == INVALID_STRING_ID; });
 
	if (it == std::end(_text_effects)) it = _text_effects.emplace(std::end(_text_effects));
 
	if (it == std::end(_text_effects)) {
 
		/* _text_effects.size() is the maximum ID + 1 that has been allocated. We should not allocate INVALID_TE_ID or beyond. */
 
		if (_text_effects.size() >= INVALID_TE_ID) return INVALID_TE_ID;
 
		it = _text_effects.emplace(std::end(_text_effects));
 
	}
 

	
 
	TextEffect &te = *it;
 

	
0 comments (0 inline, 0 general)