From: NHOrus Date: Tue, 5 Sep 2017 14:46:38 +0000 (+0300) Subject: Removed old copy-paste error X-Git-Tag: 1.5~22 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=0dd40bba32c9b5225e4d2126a50b7d6516791d06;p=open-adventure.git Removed old copy-paste error Put numdie bounds check in croak to prevent OOB access on negative numdie while preserving tests --- diff --git a/main.c b/main.c index 0556c01..1b725c9 100644 --- a/main.c +++ b/main.c @@ -85,7 +85,6 @@ int main(int argc, char *argv[]) fprintf(stderr, "advent: can't open save file %s for read\n", optarg); - signal(SIGINT, sig_handler); break; #endif default: @@ -461,6 +460,8 @@ static bool dwarfmove(void) static void croak(void) /* Okay, he's dead. Let's get on with it. */ { + if (game.numdie < 0) + game.numdie = 0; const char* query = obituaries[game.numdie].query; const char* yes_response = obituaries[game.numdie].yes_response; ++game.numdie; diff --git a/saveresume.c b/saveresume.c index c5d5181..799e7af 100644 --- a/saveresume.c +++ b/saveresume.c @@ -146,9 +146,9 @@ bool is_valid(struct game_t valgame) } /* Bounds check for locations */ - if ( valgame.chloc < -1 || valgame.chloc > NLOCATIONS || - valgame.chloc2 < -1 || valgame.chloc2 > NLOCATIONS || - valgame.loc < -1 || valgame.loc > NLOCATIONS || + if ( valgame.chloc < -1 || valgame.chloc > NLOCATIONS || + valgame.chloc2 < -1 || valgame.chloc2 > NLOCATIONS || + valgame.loc < -1 || valgame.loc > NLOCATIONS || valgame.newloc < -1 || valgame.newloc > NLOCATIONS || valgame.oldloc < -1 || valgame.oldloc > NLOCATIONS || valgame.oldlc2 < -1 || valgame.oldlc2 > NLOCATIONS) { @@ -171,7 +171,7 @@ bool is_valid(struct game_t valgame) /* Bounds check for dwarves */ if (valgame.dtotal < 0 || valgame.dtotal > NDWARVES || - valgame.dkill < 0 || valgame.dkill > NDWARVES) { + valgame.dkill < 0 || valgame.dkill > NDWARVES) { return false; }