Skip to content

Commit

Permalink
Protect against overflow when adding a ghost to the monster rating
Browse files Browse the repository at this point in the history
Also adjust, when possible, the monster rating for skipping a ghost in chunk_copy().
  • Loading branch information
backwardsEric authored and NickMcConnell committed Jun 12, 2024
1 parent 1c6b7b3 commit ec2db66
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/gen-chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,15 @@ bool chunk_copy(struct chunk *dest, struct player *p, struct chunk *source,

delete_monster_idx(dest, skipped_ghost_id);
*dest->ghost = preserved_ghost;
/*
* Compensate for the change to monster rating, but do
* nothing if it saturated: do not know what to subtract
* in that case.
*/
if (dest->mon_rating != UINT32_MAX) {
assert(dest->mon_rating >= 10);
dest->mon_rating -= 10;
}
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/mon-make.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ bool prepare_ghost(struct chunk *c, int r_idx, struct monster *mon,
}

/* Increase the level feeling */
c->mon_rating += 10;
add_to_monster_rating(c, 10);

/* Player ghosts are "seen" whenever generated. */
lore->sights = 1;
Expand Down

0 comments on commit ec2db66

Please sign in to comment.