fix Qt use-after-free reading the player name

Closes #1673
This commit is contained in:
Crissman Loomis
2026-09-11 10:02:18 -04:00
committed by nhmall
parent 1106456195
commit 55769ca9f0
+4 -1
View File
@@ -559,7 +559,10 @@ void NetHackQtPlayerSelector::plnamePlayVsQuit()
// the line edit widget for the name field has received input
void NetHackQtPlayerSelector::selectName(const QString& n)
{
const char *name_str = n.toLatin1().constData();
// the QByteArray has to outlive name_str; calling constData() on
// the temporary returned by toLatin1() leaves it dangling
QByteArray name_bytes = n.toLatin1();
const char *name_str = name_bytes.constData();
// skip any leading spaces
// (it would be better to set up a validator that rejects leading spaces)
while (*name_str == ' ')