From bfc6619c03b460f7c2d5d96f39d17c2a4428f360 Mon Sep 17 00:00:00 2001 From: sbird Date: Wed, 18 Jan 2023 23:34:27 +0100 Subject: [PATCH] [script-command, dynmultichoice] early expand placeholders --- src/scrcmd.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/scrcmd.c b/src/scrcmd.c index bb253a20c5..4599bc8bb4 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -1414,11 +1414,8 @@ bool8 ScrCmd_dynmultichoice(struct ScriptContext *ctx) items = AllocZeroed(sizeof(struct ListMenuItem) * argc); for (i = 0; i < argc; ++i) { - u8 *nameBuffer = Alloc(100); struct ListMenuItem *currentItem = MultichoiceDynamic_PeekElementAt(i); - StringExpandPlaceholders(nameBuffer, currentItem->name); - items[i].name = nameBuffer; - items[i].id = currentItem->id; + items[i] = *currentItem; if (currentItem->id == initialSelected) initialRow = i; } @@ -1440,9 +1437,13 @@ bool8 ScrCmd_dynmultichoice(struct ScriptContext *ctx) bool8 ScrCmd_dynmultipush(struct ScriptContext *ctx) { + u8 *nameBuffer = Alloc(100); const u8 *name = (const u8*) ScriptReadWord(ctx); u32 id = VarGet(ScriptReadHalfword(ctx)); - struct ListMenuItem item = {.name = name, .id = id}; + struct ListMenuItem item; + StringExpandPlaceholders(nameBuffer, name); + item.name = nameBuffer; + item.id = id; MultichoiceDynamic_PushElement(item); }