]> granicus.if.org Git - nethack/commitdiff
Add sanity checking for light sources
authorPasi Kallinen <paxed@alt.org>
Tue, 27 Oct 2015 16:36:07 +0000 (18:36 +0200)
committerPasi Kallinen <paxed@alt.org>
Tue, 27 Oct 2015 16:36:07 +0000 (18:36 +0200)
include/extern.h
src/cmd.c
src/light.c

index bd22f7826f44a9be0b70941eef506f1d61172427..22df5471bd3f6c6b1beab62dc0b843b72868f88e 100644 (file)
@@ -971,6 +971,7 @@ E struct monst *FDECL(find_mid, (unsigned, unsigned));
 E void FDECL(save_light_sources, (int, int, int));
 E void FDECL(restore_light_sources, (int));
 E void FDECL(relink_light_sources, (BOOLEAN_P));
+E void NDECL(light_sources_sanity_check);
 E void FDECL(obj_move_light_source, (struct obj *, struct obj *));
 E boolean NDECL(any_light_source);
 E void FDECL(snuff_light_source, (int, int));
index ee37e94b69a179092c22cdd3ce3bb7a780f1aa92..6cf2363a31ae42b5e05e4b5081c96d4bc73d8176 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -3069,6 +3069,7 @@ sanity_check()
     obj_sanity_check();
     timer_sanity_check();
     mon_sanity_check();
+    light_sources_sanity_check();
 }
 
 #ifdef DEBUG_MIGRATING_MONS
index a0961315be50a09608c9297b767c2df10d79a8ea..7f2f6355b5a8c54b85d05fd86c12c7119b7ed12e 100644 (file)
@@ -383,6 +383,31 @@ boolean write_it;
     return count;
 }
 
+void
+light_sources_sanity_check()
+{
+    light_source *ls;
+    unsigned int auint;
+
+    for (ls = light_base; ls; ls = ls->next) {
+        if (!ls->id.a_monst)
+            panic("insane light source: no id!");
+        if (ls->type == LS_OBJECT) {
+            struct obj *otmp = (struct obj *) ls->id.a_obj;
+            auint = otmp->o_id;
+            if (find_oid(auint) != otmp)
+                panic("insane light source: can't find obj #%u!", auint);
+        } else if (ls->type == LS_MONSTER) {
+            struct monst *mtmp = (struct monst *) ls->id.a_monst;
+            auint = mtmp->m_id;
+            if (find_mid(auint, FM_EVERYWHERE) != mtmp)
+                panic("insane light source: can't find mon #%u!", auint);
+        } else {
+            panic("insane light source: bad ls type %d", ls->type);
+        }
+    }
+}
+
 /* Write a light source structure to disk. */
 STATIC_OVL void
 write_ls(fd, ls)