diff --git a/guess.c b/guess.c index f635fec..37195b4 100644 --- a/guess.c +++ b/guess.c @@ -380,6 +380,7 @@ static bool is_markable(const game_params *params, pegrow pegs) for (i = 0; i < params->npegs; i++) { int c = pegs->pegs[i]; if (c > 0) { + assert(c <= params->ncolours); colcount->pegs[c-1]++; nset++; } @@ -462,6 +463,9 @@ static void decode_ui(game_ui *ui, const char *encoding) const char *p = encoding; for (i = 0; i < ui->curr_pegs->npegs; i++) { ui->curr_pegs->pegs[i] = atoi(p); + if (ui->curr_pegs->pegs[i] < 0 || + ui->curr_pegs->pegs[i] > ui->params.ncolours) + ui->curr_pegs->pegs[i] = 0; /* Remove invalid pegs. */ while (*p && isdigit((unsigned char)*p)) p++; if (*p == '_') { /* NB: old versions didn't store holds */