diff --git a/include/game.h b/include/game.h index ca18eae..7451153 100644 --- a/include/game.h +++ b/include/game.h @@ -6,7 +6,13 @@ #define MAX_FILENAME 256 #define MAX_MESSAGE 256 -#define MAX_WORDS 10000 +/* Reduce MAX_WORDS for DOS to avoid stack overflow */ +#ifdef PLATFORM_DOS + #define MAX_WORDS 2000 +#else + #define MAX_WORDS 10000 +#endif + #define WORD_LENGTH 5 #define MAX_GUESSES 6 diff --git a/src/game.c b/src/game.c index 3afe2a7..a27c519 100644 --- a/src/game.c +++ b/src/game.c @@ -36,9 +36,10 @@ void init_game(GameState *game) { /* Check guess against target word */ void check_guess(GameState *game, const char *guess, int *colors) { + int i, j; + char target_copy[WORD_LENGTH + 1]; char guess_copy[WORD_LENGTH + 1]; - int i, j; int target_used[WORD_LENGTH] = {0}; strcpy(target_copy, game->target_word); @@ -46,7 +47,7 @@ void check_guess(GameState *game, const char *guess, int *colors) { /* Ensure uppercase */ for (i = 0; i < WORD_LENGTH; i++) { - guess_copy[i] = toupper(guess_copy[i]); + guess_copy[i] = toupper((unsigned char)guess_copy[i]); } /* Initialize all as absent */ @@ -97,7 +98,7 @@ int make_guess(GameState *game, const char *guess) { strcpy(upper_guess, guess); for (i = 0; i < WORD_LENGTH; i++) { - upper_guess[i] = toupper(upper_guess[i]); + upper_guess[i] = toupper((unsigned char)upper_guess[i]); } if (!is_valid_word(game, upper_guess)) { diff --git a/src/main.c b/src/main.c index 89f3ea6..0e0529c 100644 --- a/src/main.c +++ b/src/main.c @@ -196,7 +196,7 @@ int main_game_loop(int argc, char *argv[]) { } } else if ((key >= 'a' && key <= 'z') || (key >= 'A' && key <= 'Z')) { if (game.current_guess_length < WORD_LENGTH) { - game.current_guess[game.current_guess_length] = toupper(key); + game.current_guess[game.current_guess_length] = toupper((unsigned char)key); game.current_guess_length++; game.current_guess[game.current_guess_length] = '\0'; strcpy(message, ""); diff --git a/src/ui.c b/src/ui.c index f7d69f3..34e9109 100644 --- a/src/ui.c +++ b/src/ui.c @@ -143,7 +143,7 @@ void draw_message(WINDOW *win, const char *message, const int y, const int color /* Draw game instructions */ void draw_instructions(WINDOW *win, int y) { - const char *instructions[] = { + static const char *instructions[] = { "Guess the 5-letter word in 6 tries!", "", "Colors: GREEN=Correct, YELLOW=Wrong position, RED=Not in word", diff --git a/src/words.c b/src/words.c index bf1d67d..e9284e5 100644 --- a/src/words.c +++ b/src/words.c @@ -11,7 +11,7 @@ #include /* Try to open a wordlist file, using multiple fallback locations */ -static FILE* open_wordlist(const char *filename) { +static FILE *open_wordlist(const char *filename) { FILE *file; char filepath[512]; #if HAS_HOME_ENV @@ -47,7 +47,7 @@ static FILE* open_wordlist(const char *filename) { void to_upper(char *str) { int i; for (i = 0; str[i]; i++) { - str[i] = toupper(str[i]); + str[i] = toupper((unsigned char)str[i]); } }