comparison arogue7/player.c @ 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 e52a8a7ad4c5
children
comparison
equal deleted inserted replaced
312:029c1f5c5588 313:2f75940cc544
679 return(FALSE); 679 return(FALSE);
680 } 680 }
681 } 681 }
682 else { 682 else {
683 /* Now display the possible spells */ 683 /* Now display the possible spells */
684 /* type_cap is a workaround for code that tried to capitalize type by
685 * temporarily modifying it in place. */
686 char type_cap = toupper(type[0]);
684 wclear(hw); 687 wclear(hw);
685 touchwin(hw); 688 touchwin(hw);
686 wmove(hw, 2, 0); 689 wmove(hw, 2, 0);
687 *type = toupper(*type); 690 wprintw(hw, " Cost %c%s", type_cap, type + 1);
688 wprintw(hw, " Cost %s", type);
689 *type = tolower(*type);
690 mvwaddstr(hw, 3, 0, 691 mvwaddstr(hw, 3, 0,
691 "-----------------------------------------------"); 692 "-----------------------------------------------");
692 maxlen = 47; /* Maximum width of header */ 693 maxlen = 47; /* Maximum width of header */
693 694
694 for (i=0; i<num_spells; i++) { 695 for (i=0; i<num_spells; i++) {
731 /* Place an end marker for the items */ 732 /* Place an end marker for the items */
732 Dispitems[num_spells].mi_name = 0; 733 Dispitems[num_spells].mi_name = 0;
733 734
734 /* Design prompts */ 735 /* Design prompts */
735 sprintf(label, "Current %s power is %d", type, spell_left); 736 sprintf(label, "Current %s power is %d", type, spell_left);
736 *type = toupper(*type); 737 sprintf(title, " Cost %c%s", type_cap, type + 1);
737 sprintf(title, " Cost %s", type);
738 *type = tolower(*type);
739 sprintf(prbuf, "Select a %s or press Cancl to continue.", type); 738 sprintf(prbuf, "Select a %s or press Cancl to continue.", type);
740 739
741 /* Set up the main menu structure */ 740 /* Set up the main menu structure */
742 Display.m_label = label; 741 Display.m_label = label;
743 Display.m_title = title; 742 Display.m_title = title;