From 6e19ec731eaf8018163a05a20844b7e442f71425 Mon Sep 17 00:00:00 2001 From: "Ignacio R. Morelle" Date: Sat, 5 Mar 2016 23:14:15 -0300 Subject: [PATCH] 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. --- changelog | 3 +++ players_changelog | 4 ++++ src/gui/dialogs/unit_attack.cpp | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/changelog b/changelog index 5128b99a000f..a21edd317a20 100644 --- a/changelog +++ b/changelog @@ -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 diff --git a/players_changelog b/players_changelog index bd1f717695c2..410b683b752b 100644 --- a/players_changelog +++ b/players_changelog @@ -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: diff --git a/src/gui/dialogs/unit_attack.cpp b/src/gui/dialogs/unit_attack.cpp index a0f7ba039a0e..6553272b4a94 100644 --- a/src/gui/dialogs/unit_attack.cpp +++ b/src/gui/dialogs/unit_attack.cpp @@ -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()) {