# HG changeset patch # User John "Elwin" Edwards # Date 1634690340 14400 # Node ID 2f75940cc54403adfbad562a9914d0c8d5dceefa # Parent 029c1f5c558875ed1107f4ebbde26382b0f13f44 Advanced Rogue 7: fix a string literal overwrite. pick_spell() attempted to capitalize type by overwriting the first character, changing it back later. All calls of pick_spell passed a string literal as type, and string literals should be considered immutable. This has been fixed by using a separate variable for the capitalized first character. XRogue already has a similar fix. Reported by John Harris of @Play. diff -r 029c1f5c5588 -r 2f75940cc544 arogue7/player.c --- a/arogue7/player.c Tue May 11 22:30:03 2021 -0400 +++ b/arogue7/player.c Tue Oct 19 20:39:00 2021 -0400 @@ -681,12 +681,13 @@ } else { /* Now display the possible spells */ + /* type_cap is a workaround for code that tried to capitalize type by + * temporarily modifying it in place. */ + char type_cap = toupper(type[0]); wclear(hw); touchwin(hw); wmove(hw, 2, 0); - *type = toupper(*type); - wprintw(hw, " Cost %s", type); - *type = tolower(*type); + wprintw(hw, " Cost %c%s", type_cap, type + 1); mvwaddstr(hw, 3, 0, "-----------------------------------------------"); maxlen = 47; /* Maximum width of header */ @@ -733,9 +734,7 @@ /* Design prompts */ sprintf(label, "Current %s power is %d", type, spell_left); - *type = toupper(*type); - sprintf(title, " Cost %s", type); - *type = tolower(*type); + sprintf(title, " Cost %c%s", type_cap, type + 1); sprintf(prbuf, "Select a %s or press Cancl to continue.", type); /* Set up the main menu structure */