gui2/tunit_attack: Fix non-deterministic crashes

t_string's implicit conversion to const std::string& returns a reference
to a(n aggregate class) field that gets destroyed as soon as the
t_string is, so binding this to a const reference does not extend the
referenced object's lifetime, resulting in a dangling reference and UB.
This commit is contained in:
Ignacio R. Morelle 2016-03-05 23:14:15 -03:00
parent 3989199a88
commit 6e19ec731e
3 changed files with 9 additions and 2 deletions

View file

@ -1,6 +1,9 @@
Version 1.13.3+dev:
* Language and i18n:
* Updated translations:
* Miscellaneous and bug fixes:
* Fix non-deterministic crashes in the Attack Unit dialog resulting from
invalid memory references (regression introduced in 1.13.3).
Version 1.13.3:
* Greatly improved SDL 2 support. SDL 2 is now used by default build when

View file

@ -6,6 +6,10 @@ Version 1.13.3+dev:
* Language and i18n:
* Updated translations:
* Miscellaneous and bug fixes:
* Fix non-deterministic crashes in the Attack Unit dialog (regression
introduced in 1.13.3).
Version 1.13.3:
* SDL 2 is now used by default when building. This fixes the following bugs,
among others:

View file

@ -200,8 +200,8 @@ static void set_weapon_info(twindow& window,
const SDL_Color d_cth_color =
int_to_color(game_config::red_to_green(defender.chance_to_hit));
const std::string& attw_name = !attacker_weapon.name().empty() ? attacker_weapon.name() : " ";
const std::string& defw_name = !defender_weapon.name().empty() ? defender_weapon.name() : " ";
const std::string attw_name = !attacker_weapon.name().empty() ? attacker_weapon.name() : " ";
const std::string defw_name = !defender_weapon.name().empty() ? defender_weapon.name() : " ";
std::string range = attacker_weapon.range().empty() ? defender_weapon.range() : attacker_weapon.range();
if (!range.empty()) {