snake.c
1 2
|
// ------------- DO NOT MODIFY ANYTHING ABOVE THIS LINE ------------------
// Check validity of the board before rendering!
|
So above this line, there are multiple train wrecks.
> initialize_game(&game, argv[2]);
Routinely ignores the return result, because it's declared like this.
> board_init_status_t initialize_game(game_t* game, char* board_rep);
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
board_init_status_t initialize_game(game_t* game, char* board_rep) {
// TODO: implement!
game->game_over = 0;
game->score = 0;
if (board_rep == NULL)
{
initialize_default_board(game->board);
}
else
{
decompress_board_str(game->board, board_rep);
}
return INIT_SUCCESS;
}
|
Both these functions return a result (which you ignore).
decompress_board_str can return a failure, but you just claim success anyway.
Not that it matters, the caller doesn't pay any attention to it either.
In the midst of returning an error, it leaves the cells pointer as uninitialised garbage.
So much for "Check validity".
The best you can hope to achieve is by doing at least this at the start of initialize_game.
game->board->cells = NULL;