From 970a8ee89dbc44d107e13c34768f4d9a145dbfed Mon Sep 17 00:00:00 2001 From: toaster Date: Wed, 6 Feb 2019 13:28:21 +0000 Subject: [PATCH] Fix off-by-one errors in item odds, and add a little assert to make an assumption in this function that was being violated more explicit. --- src/k_kart.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 49fd54e6..018519ca 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -616,7 +616,7 @@ static INT32 K_KartGetItemOdds(UINT8 pos, SINT8 item, fixed_t mashed) UINT8 pingame = 0, pexiting = 0, pinvin = 0; SINT8 first = -1, second = -1; INT32 secondist = 0; - boolean itemenabled[NUMKARTRESULTS] = { + boolean itemenabled[NUMKARTRESULTS-1] = { cv_sneaker.value, cv_rocketsneaker.value, cv_invincibility.value, @@ -640,7 +640,9 @@ static INT32 K_KartGetItemOdds(UINT8 pos, SINT8 item, fixed_t mashed) cv_dualjawz.value }; - if (!itemenabled[item] && !modeattacking) + I_Assert(item > KITEM_NONE); // too many off by one scenarioes. + + if (!itemenabled[item-1] && !modeattacking) return 0; if (G_BattleGametype()) @@ -761,7 +763,7 @@ static INT32 K_FindUseodds(player_t *player, fixed_t mashed, INT32 pingame, INT3 break; } - for (j = 0; j < NUMKARTRESULTS; j++) + for (j = 1; j < NUMKARTRESULTS; j++) { if (K_KartGetItemOdds(i, j, mashed) > 0) {