fix pull request #621 - potential divide by 0
The pull request by argrath changes weight_cap() to never return a value less than 1 because try_lift() divides by that return value and a 0 would trigger a crash. The code involved is used when attempting to pull a monster out of a pit via #untrap. I'm fairly sure that weight_cap() can never produce a value that's less than 1 already, but have put in a variation of the PR's fix. I've also implemented a different fix that removes the division from try_lift(). The original code seems to have gone out of its way to avoid calculating inv_weight() twice, but doing the latter (for the once in a hundred games where it might happen) greatly simplifies things by removing details of carrying capacity. Fixes #621
This commit is contained in:
@@ -3330,8 +3330,6 @@ weight_cap(void)
|
||||
if (EWounded_legs & RIGHT_SIDE)
|
||||
carrcap -= 100;
|
||||
}
|
||||
if (carrcap < 0)
|
||||
carrcap = 0;
|
||||
}
|
||||
|
||||
if (ELevitation != save_ELev || BLevitation != save_BLev) {
|
||||
@@ -3340,7 +3338,7 @@ weight_cap(void)
|
||||
float_vs_flight();
|
||||
}
|
||||
|
||||
return (int) carrcap;
|
||||
return (int) max(carrcap, 1L); /* never return 0 */
|
||||
}
|
||||
|
||||
/* returns how far beyond the normal capacity the player is currently. */
|
||||
|
||||
Reference in New Issue
Block a user