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 i, alreadyUsed = 0;
for (i = 0; i < gs->wordLength; i++) {
for (unsigned i = 0; i < strlen(gs->wrongCharacters); i++) {
if (gs->wrongCharacters[i] == wrongchar) {
alreadyUsed = 1;
return 0; // already used
}
}
if (!alreadyUsed) {
gs->wrongCharacters[strlen(gs->wrongCharacters)] = wrongchar;
drawAlphabet(gs, wrongchar);
drawFigure(gs, 1);
return 1;
} else {
return 0;
}
// not yet used
gs->wrongCharacters[strlen(gs->wrongCharacters)] = wrongchar;
drawAlphabet(gs, wrongchar);
drawFigure(gs, 1);
return 1;
}
int checkWin(game_state *gs) {