take popup option names by const reference, not by pointer

POPUP_OPTION copies the name it is given -- `this->name = *newName` into a
std::wstring member -- but its constructor took a std::wstring*, so 64 call
sites spelled the argument `&std::wstring( pStr )`. Taking the address of a
temporary is ill-formed, and clang refuses it outright:

    error: taking the address of a temporary object of type 'std::wstring'

It happens to work under MSVC because the temporary outlives the call, dying
at the end of the full expression rather than before the copy. Nothing was
corrupt; the code was just spelling "pass me a string" in a way the language
does not allow.

A const reference says what these functions actually want, so the call sites
lose the &, and the two places that allocated a string purely to have an
address to pass -- POPUP_SUB_POPUP_OPTION's default constructor, which carried
a "TODO: possible memmory leak!" saying as much, and a "Dummy generator"
option -- stop leaking one.

Converted: POPUP_OPTION's constructor and setName, POPUP::addOption and
addSubMenuOption, and both POPUP_SUB_POPUP_OPTION constructors. The popupDef
family in popup_definition.* keeps its std::wstring* because it owns what it
is handed and stores the pointer; that is a different design and a different
change. The three calls it makes into the converted API now dereference.

Verification:
    grep -rn '&std::wstring' --include=*.cpp --include=*.h .   # nothing
    ninja -C build parse             # no popup_* or SkillMenu sites remain
    ninja -C build -k 0              # Release, four applications, green
    ninja -C build-debug -k 0        # Debug, four applications, green

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Marco Antonio J. Costa
2026-07-23 19:29:55 -03:00
committed by majcosta
co-authored by Claude Opus 4.8
parent 83b637aa73
commit 5e2982c509
7 changed files with 96 additions and 96 deletions
+9 -9
View File
@@ -140,9 +140,9 @@ POPUP_OPTION::~POPUP_OPTION(void)
}
POPUP_OPTION::POPUP_OPTION(std::wstring *newName, popupCallback * newFunction)
POPUP_OPTION::POPUP_OPTION(const std::wstring& newName, popupCallback * newFunction)
{
this->name = *newName;
this->name = newName;
this->action = newFunction;
this->avail = 0;
@@ -161,9 +161,9 @@ POPUP_OPTION::POPUP_OPTION(std::wstring *newName, popupCallback * newFunction)
this->color_shade = FONT_GRAY7 ;
}
BOOLEAN POPUP_OPTION::setName( std::wstring * newName )
BOOLEAN POPUP_OPTION::setName( const std::wstring& newName )
{
this->name = *newName;
this->name = newName;
return TRUE;
}
@@ -236,19 +236,19 @@ BOOLEAN POPUP_OPTION::forceRun()
//////////////////////////////////////////////////////////////////
// constructor
POPUP_SUB_POPUP_OPTION::POPUP_SUB_POPUP_OPTION(void) : POPUP_OPTION(new std::wstring(L"Unnamed subPopup"),NULL) //TODO: possible memmory leak!
POPUP_SUB_POPUP_OPTION::POPUP_SUB_POPUP_OPTION(void) : POPUP_OPTION(L"Unnamed subPopup", NULL)
{
this->parent = NULL;
this->initSubPopup();
}
POPUP_SUB_POPUP_OPTION::POPUP_SUB_POPUP_OPTION(std::wstring* name) : POPUP_OPTION(name, NULL)
POPUP_SUB_POPUP_OPTION::POPUP_SUB_POPUP_OPTION(const std::wstring& name) : POPUP_OPTION(name, NULL)
{
this->parent = NULL;
this->initSubPopup();
}
POPUP_SUB_POPUP_OPTION::POPUP_SUB_POPUP_OPTION(std::wstring* newName, const POPUP * parent) : POPUP_OPTION(newName, NULL)
POPUP_SUB_POPUP_OPTION::POPUP_SUB_POPUP_OPTION(const std::wstring& newName, const POPUP * parent) : POPUP_OPTION(newName, NULL)
{
this->parent = parent;
this->initSubPopup();
@@ -562,7 +562,7 @@ void POPUP::setInitialValues(void)
// setup functions
POPUP_OPTION * POPUP::addOption(std::wstring * name, popupCallback* action)
POPUP_OPTION * POPUP::addOption(const std::wstring& name, popupCallback* action)
{
if (this->optionCount < POPUP_MAX_OPTIONS)
{
@@ -605,7 +605,7 @@ POPUP_OPTION * POPUP::getOption(UINT16 n)
return NULL;
}
POPUP * POPUP::addSubMenuOption(std::wstring * name)
POPUP * POPUP::addSubMenuOption(const std::wstring& name)
{
if (this->subPopupOptionCount < POPUP_MAX_SUB_POPUPS)
{