From 8bec79ea1142f0a3f281a13610eec1ad7aa74236 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 18 Jan 2022 05:04:23 +0200 Subject: [PATCH 45/45] Fix message about an action blocking another As action_name_translation() always returns the same pointer to the static string it modifies, name of the blocked action was overwritten with the name of the blocker action, before it was sent to the client. Reported by ddeanbrown See osdn #43643 Signed-off-by: Marko Lindqvist --- common/actions.c | 4 ++++ server/unithand.c | 19 ++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/common/actions.c b/common/actions.c index fadc90ee49..707b2c92af 100644 --- a/common/actions.c +++ b/common/actions.c @@ -1935,6 +1935,10 @@ const char *action_rule_name(const struct action *action) /**********************************************************************//** Get the action name used when displaying the action in the UI. Nothing is added to the UI name. + + This always returns the same static string, just modified according + to the call. Copy the result if you want it to remain valid over + another call to this function. **************************************************************************/ const char *action_name_translation(const struct action *action) { diff --git a/server/unithand.c b/server/unithand.c index 6f6d8c0cfc..0e2973fa80 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -2781,13 +2781,18 @@ void illegal_action_msg(struct player *pplayer, utype_name_translation(explnat->no_tgt_utype)); break; case ANEK_ACTION_BLOCKS: - notify_player(pplayer, unit_tile(actor), - event, ftc_server, - /* TRANS: Freight ... Recycle Unit ... Help Wonder ... */ - _("Your %s can't do %s when %s is legal."), - unit_name_translation(actor), - action_id_name_translation(stopped_action), - action_id_name_translation(explnat->blocker->id)); + { + char *stop_act_name = fc_strdup(action_id_name_translation(stopped_action)); + + notify_player(pplayer, unit_tile(actor), + event, ftc_server, + /* TRANS: Freight ... Recycle Unit ... Help Wonder ... */ + _("Your %s can't do %s when %s is legal."), + unit_name_translation(actor), + stop_act_name, + action_id_name_translation(explnat->blocker->id)); + free(stop_act_name); + } break; case ANEK_UNKNOWN: notify_player(pplayer, unit_tile(actor), -- 2.34.1