summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2013-09-08 16:29:01 +0200
committerBardur Arantsson <bardur@scientician.net>2013-09-27 14:46:43 +0200
commite639beb074dec2d641b13bdb4f2d080b50dd55cb (patch)
treec191c1b81de7c5aa3679c5ad398e7095b48f888f /src
parent5a60ce1f8ab8a6a34cf55b637dd601b5d4422197 (diff)
Fix undefined behavior for HP calculation at birth
Diffstat (limited to 'src')
-rw-r--r--src/birth.cc3
-rw-r--r--src/xtra1.cc2
2 files changed, 5 insertions, 0 deletions
diff --git a/src/birth.cc b/src/birth.cc
index 51cd092b..8612efdc 100644
--- a/src/birth.cc
+++ b/src/birth.cc
@@ -810,6 +810,9 @@ static void player_wipe(void)
/* Hack -- zero the struct */
WIPE(p_ptr, player_type);
+ /* Level 1 is the first level */
+ p_ptr->lev = 1;
+
/* Not dead yet */
p_ptr->lives = 0;
diff --git a/src/xtra1.cc b/src/xtra1.cc
index 821fe508..e38c719d 100644
--- a/src/xtra1.cc
+++ b/src/xtra1.cc
@@ -1872,6 +1872,8 @@ void calc_hitpoints(void)
bonus = ((int)(adj_con_mhp[p_ptr->stat_ind[A_CON]]) - 128);
/* Calculate hitpoints */
+ assert(p_ptr->lev - 1 >= 0);
+ assert(p_ptr->lev - 1 < PY_MAX_LEVEL);
mhp = player_hp[p_ptr->lev - 1] + (bonus * p_ptr->lev / 2);
/* Always have at least one hitpoint per level */