changeset 313:2f75940cc544

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.
author John "Elwin" Edwards
date Tue, 19 Oct 2021 20:39:00 -0400
parents 029c1f5c5588
children 2f0eb38da609
files arogue7/player.c
diffstat 1 files changed, 5 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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 */