From 4e299e4f836ca7930820f50f683664ca146d02e7 Mon Sep 17 00:00:00 2001 From: zicodxx Date: Sat, 24 Sep 2011 11:15:24 +0200 Subject: [PATCH] Consistency check for segment number in find_vector_intersection() and obj_create(); Added more debug output for invalid segment numberin get_seg_masks() --- CHANGELOG.txt | 4 ++++ main/fvi.c | 12 ++++++++++++ main/gameseg.c | 4 +++- main/object.c | 5 ++++- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index c58687cbd..a59409447 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,9 @@ D1X-Rebirth Changelog +20110924 +-------- +main/fvi.c, main/gameseg.c, main/object.c: Consistency check for segment number in find_vector_intersection() and obj_create(); Added more debug output for invalid segment numberin get_seg_masks() + 20110923 -------- main/state.c: When restoring Coop players and make turn them into ghosts perform a check if this player is actually a valid player so we do not just blindly use any object number from a possibly uninitialized player structure diff --git a/main/fvi.c b/main/fvi.c index 27812388f..16c9b6bcb 100644 --- a/main/fvi.c +++ b/main/fvi.c @@ -644,6 +644,18 @@ int find_vector_intersection(fvi_query *fq,fvi_info *hit_data) //check to make sure start point is in seg its supposed to be in //Assert(check_point_in_seg(p0,startseg,0).centermask==0); //start point not in seg + // invalid segnum, so say there is no hit. + if(fq->startseg < 0 || fq->startseg > Highest_segment_index) + { + + hit_data->hit_type = HIT_BAD_P0; + hit_data->hit_pnt = *fq->p0; + hit_data->hit_seg = hit_data->hit_side = hit_data->hit_object = 0; + hit_data->hit_side_seg = -1; + + return hit_data->hit_type; + } + // Viewer is not in segment as claimed, so say there is no hit. if(!(get_seg_masks(fq->p0,fq->startseg,0,__FILE__,__LINE__).centermask==0)) { diff --git a/main/gameseg.c b/main/gameseg.c index 54acda6a9..b81d9d70c 100644 --- a/main/gameseg.c +++ b/main/gameseg.c @@ -31,6 +31,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "wall.h" #include "fuelcen.h" #include "byteswap.h" +#include "mission.h" #ifdef RCS static char rcsid[] = "$Id: gameseg.c,v 1.1.1.1 2006/03/17 19:45:01 zicodxx Exp $"; @@ -304,9 +305,10 @@ segmasks get_seg_masks(vms_vector *checkp,int segnum,fix rad,char *calling_file, int num_faces; int vertex_list[6]; segment *seg; + extern int Current_level_num; if (segnum < 0 || segnum > Highest_segment_index) - Error("segnum == %i (%i) in get_seg_masks()\ncheckp: %i,%i,%i, rad: %i\nfrom file: %s, line: %i\nPlease report this bug.\n",segnum,Highest_segment_index,checkp->x,checkp->y,checkp->z,rad,calling_file,calling_linenum); + Error("segnum == %i (%i) in get_seg_masks() \ncheckp: %i,%i,%i, rad: %i \nfrom file: %s, line: %i \nMission: %s (%i) \nPlease report this bug.\n",segnum,Highest_segment_index,checkp->x,checkp->y,checkp->z,rad,calling_file,calling_linenum, Current_mission_filename, Current_level_num); Assert((segnum <= Highest_segment_index) && (segnum >= 0)); diff --git a/main/object.c b/main/object.c index bc6a6bfd2..78fddc12e 100644 --- a/main/object.c +++ b/main/object.c @@ -1101,7 +1101,10 @@ int obj_create(ubyte type,ubyte id,int segnum,vms_vector *pos, int objnum; object *obj; - Assert((segnum <= Highest_segment_index) && (segnum >= 0)); + // Some consistency checking. FIXME: Add more debug output here to probably trace all possible occurances back. + if (segnum < 0 || segnum > Highest_segment_index) + return -1; + Assert(ctype <= CT_CNTRLCEN); if (type==OBJ_DEBRIS && Debris_object_count>=Max_debris_objects && !PERSISTENT_DEBRIS)