Skip to content

Commit

Permalink
fix UB - index out of bounds caused by typo and don't print garbage w…
Browse files Browse the repository at this point in the history
…hen parsed board is shorter then expected.
  • Loading branch information
panstromek committed Feb 20, 2022
1 parent 8de4293 commit 29e5021
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions game.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,14 @@ setup_game( const char *file_name, int *side_to_move ) {
break;
default:
#if TEXT_BASED
printf( "%s '%c' %s\n", BAD_CHARACTER_ERROR, buffer[pos],
if (buffer[token] != '\0') // Don't log if string ended
printf( "%s '%c' %s\n", BAD_CHARACTER_ERROR, buffer[token],
GAME_FILE_TEXT);
#endif
break;
}
token++;
if (buffer[token] != '\0') // Don't increment if string ended
token++;
}

fgets( buffer, 10, stream );
Expand Down

0 comments on commit 29e5021

Please sign in to comment.