diff --git a/include/asm/lexer.hpp b/include/asm/lexer.hpp index aea7a991..0bcfb95a 100644 --- a/include/asm/lexer.hpp +++ b/include/asm/lexer.hpp @@ -4,6 +4,8 @@ #define RGBDS_ASM_LEXER_H #include +#include +#include #include "platform.hpp" // SSIZE_MAX @@ -25,7 +27,7 @@ enum LexerMode { }; struct Expansion { - char *name; + std::optional name; union { char const *unowned; char *owned; diff --git a/src/asm/lexer.cpp b/src/asm/lexer.cpp index 4496aeaf..0400b112 100644 --- a/src/asm/lexer.cpp +++ b/src/asm/lexer.cpp @@ -10,9 +10,11 @@ #include #include #include +#include #include #include #include +#include #include #include #ifndef _MSC_VER @@ -509,7 +511,7 @@ static void beginExpansion(char const *str, bool owned, char const *name) lexer_CheckRecursionDepth(); lexerState->expansions.push_front({ - .name = name ? strdup(name) : nullptr, + .name = name ? std::optional(name) : std::nullopt, .contents = { .unowned = str }, .size = size, .offset = 0, @@ -525,7 +527,6 @@ void lexer_CheckRecursionDepth() static void freeExpansion(Expansion &expansion) { - free(expansion.name); if (expansion.owned) free(expansion.contents.owned); } @@ -843,7 +844,7 @@ void lexer_DumpStringExpansions() for (Expansion &exp : lexerState->expansions) { // Only register EQUS expansions, not string args if (exp.name) - fprintf(stderr, "while expanding symbol \"%s\"\n", exp.name); + fprintf(stderr, "while expanding symbol \"%s\"\n", exp.name->c_str()); } }