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.
This commit is contained in:
John "Elwin" Edwards 2021-10-19 20:39:00 -04:00
parent 6a654fbe69
commit fb0ef69143

View file

@ -681,12 +681,13 @@ pick_spell(struct spells spells[], int ability, int num_spells, int power,
}
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 @@ pick_spell(struct spells spells[], int ability, int num_spells, int power,
/* 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 */