Fix buffer overflow (space for '\0' character missing)

This commit is contained in:
2017-08-23 22:06:49 +02:00
parent ca3347f21d
commit c1dc380ba9

View File

@@ -176,7 +176,7 @@ void initAlphabet(game_state *gs) {
break; break;
} }
} }
gs->alphabet = malloc(sizeof(char) * hasNumber ? ALPHABET : ALPHABET_NUM); gs->alphabet = malloc(sizeof(char) * ((hasNumber ? ALPHABET : ALPHABET_NUM) + 1));
strcpy(gs->alphabet, "abcdefghijklmnopqrstuvwxyz"); strcpy(gs->alphabet, "abcdefghijklmnopqrstuvwxyz");
if (hasNumber) { if (hasNumber) {
@@ -226,7 +226,7 @@ void drawGuessWord(game_state *gs) {
} }
rows++; rows++;
} }
gs->wordRows = rows; //set the number of rows for clearing the screen later gs->wordRows = rows; //set the number of rows for clearing the screen later
tempstartpos = xcounter = gs->centerx - (gs->wordLength / rows); tempstartpos = xcounter = gs->centerx - (gs->wordLength / rows);
} }
for (i = startpos; i < startpos + (gs->wordLength * 2); i++) { for (i = startpos; i < startpos + (gs->wordLength * 2); i++) {