Fixed out ouf bounds array access

This commit is contained in:
2017-08-24 00:18:51 +02:00
parent 271c1234e6
commit 8dac365357

View File

@@ -287,21 +287,18 @@ int fillCurrentWord(game_state *gs, char validchar) {
} }
int stackWrongCharacter(game_state *gs, char wrongchar) { int stackWrongCharacter(game_state *gs, char wrongchar) {
int i, alreadyUsed = 0; for (unsigned i = 0; i < strlen(gs->wrongCharacters); i++) {
for (i = 0; i < gs->wordLength; i++) {
if (gs->wrongCharacters[i] == wrongchar) { if (gs->wrongCharacters[i] == wrongchar) {
alreadyUsed = 1; return 0; // already used
} }
} }
if (!alreadyUsed) { // not yet used
gs->wrongCharacters[strlen(gs->wrongCharacters)] = wrongchar; gs->wrongCharacters[strlen(gs->wrongCharacters)] = wrongchar;
drawAlphabet(gs, wrongchar); drawAlphabet(gs, wrongchar);
drawFigure(gs, 1); drawFigure(gs, 1);
return 1; return 1;
} else {
return 0;
}
} }
int checkWin(game_state *gs) { int checkWin(game_state *gs) {