rmtew / incursion-roguelike

The legendary computer game Incursion: Hall of the Goblin King!
https://incursion-roguelike.net/
Other
9 stars 1 forks source link

NAME macro fails to cast a String to const char * correctly #16

Closed rmtew closed 3 months ago

rmtew commented 3 months ago

Walking around in Debug x64 in the starting room crashes reliably with bad char * argument to strstr.

The relevant crash is name being junk data.

    // Incursion.exe!denySpell(Monster * m, unsigned int eID) Line 271  C++
    const char* name = NAME(eID);

    if (strstr(name,"acid") || strstr(name,"vitriolic") ||
        (te->ef.eval == EA_BLAST && te->ef.xval == AD_ACID) ||

Putting a breakpoint in this function, the values of name can be observed to be always be junk in Win32 and this is a change in compiler behaviour from VS2015 to VS2022.

Expanding the NAME macro inline and comparing the results of both side by side show the expanded version and the cast operator are working. The following values are correct:

    Resource* rr = theGame->Get(eID);
    String &z = rr->GetName(0);
    const char* zs = z.GetData();
    const char* zsc = (const char*)z;

It appears that the cast operation on a ternary expression in 2022 does not classify as an operation on a String object where one of the paths returns a String& and the other a char*. In 2015 it must have.