Skip to content

Commit

Permalink
Fix crash when setting health to negative value
Browse files Browse the repository at this point in the history
  • Loading branch information
bradharding committed Oct 28, 2024
1 parent 8af07f4 commit a2bf716
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/c_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -10112,7 +10112,8 @@ static void player_cvars_func2(char *cmd, char *parms)
{
if (*parms)
{
if (sscanf(parms, "%10i", &value) == 1 && value != viewplayer->health)
if (sscanf(parms, "%10i", &value) == 1
&& (!negativehealth && value != viewplayer->health) || (negativehealth && value != viewplayer->negativehealth))
{
value = BETWEEN(((viewplayer->cheats & CF_BUDDHA) ? 1 : HUD_NUMBER_MIN), value, maxhealth);

Expand All @@ -10127,6 +10128,7 @@ static void player_cvars_func2(char *cmd, char *parms)
viewplayer->damagecount = viewplayer->health - value;

viewplayer->health = value;
viewplayer->negativehealth = value;
viewplayer->mo->health = value;
}
else
Expand All @@ -10150,6 +10152,7 @@ static void player_cvars_func2(char *cmd, char *parms)
{
viewplayer->damagecount = viewplayer->health - value;
viewplayer->health = value;
viewplayer->negativehealth = value;
viewplayer->mo->health = value;
healthcvar = true;

Expand All @@ -10165,6 +10168,7 @@ static void player_cvars_func2(char *cmd, char *parms)
{
P_UpdateHealthStat(value - viewplayer->health);
viewplayer->health = value;
viewplayer->negativehealth = value;
viewplayer->mo->health = value;
P_AddBonus();
S_StartSound(viewplayer->mo, sfx_itemup);
Expand Down
2 changes: 1 addition & 1 deletion src/st_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void STlib_UpdateBigHealthNum(st_number_t *n)
const int y = n->y;
const int width = SHORT(n->p[0]->width);

if (negativehealth && minuspatch && !viewplayer->health && viewplayer->negativehealth < 0)
if (negativehealth && minuspatch && viewplayer->negativehealth < 0)
{
int offset = 0;

Expand Down

0 comments on commit a2bf716

Please sign in to comment.