Skip to content

Commit

Permalink
gui2/tunit_attack: Fix non-deterministic crashes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
irydacea committed Mar 6, 2016
1 parent 3989199 commit 6e19ec7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions 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
Expand Down
4 changes: 4 additions & 0 deletions players_changelog
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/gui/dialogs/unit_attack.cpp
Expand Up @@ -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()) {
Expand Down

0 comments on commit 6e19ec7

Please sign in to comment.