@@ -58,11 +58,11 @@ planefunction_t ceilingfunc;
5858/* Here comes the obnoxious "visplane". */
5959
6060visplane_t visplanes [CONFIG_GAMES_NXDOOM_MAXVISPLANES ];
61+ short openings [MAXOPENINGS ];
6162visplane_t * lastvisplane ;
6263visplane_t * floorplane ;
6364visplane_t * ceilingplane ;
6465
65- short openings [MAXOPENINGS ];
6666short * lastopening ;
6767
6868/* Clip values are the solid pixel bounding the range. floorclip starts out
@@ -114,12 +114,21 @@ static void r_map_plane(int y, int x1, int x2)
114114 fixed_t length ;
115115 unsigned index ;
116116
117- #ifdef CONFIG_GAMES_NXDOOM_RANGECHECK
118- if (x2 < x1 || x1 < 0 || x2 >= viewwidth || y > viewheight )
117+ /* Ensure array indices are in range before access. */
118+
119+ if (x2 < x1 || x1 < 0 || x2 >= viewwidth )
119120 {
120- i_error ("R_MapPlane: %i, %i at %i" , x1 , x2 , y );
121+ return ;
122+ }
123+
124+ if (y < 0 )
125+ {
126+ y = 0 ;
127+ }
128+ else if (y >= viewheight )
129+ {
130+ y = viewheight - 1 ;
121131 }
122- #endif
123132
124133 if (planeheight != cachedheight [y ])
125134 {
@@ -160,27 +169,42 @@ static void r_map_plane(int y, int x1, int x2)
160169 spanfunc ();
161170}
162171
172+ static inline boolean r_row_in_range (int row )
173+ {
174+ return row >= 0 && row < SCREENHEIGHT ;
175+ }
176+
163177static void r_make_spans (int x , int t1 , int b1 , int t2 , int b2 )
164178{
179+ /* Check that row is in range before indexing arrays. */
180+
165181 while (t1 < t2 && t1 <= b1 )
166182 {
167- r_map_plane (t1 , spanstart [t1 ], x - 1 );
183+ r_map_plane (t1 , r_row_in_range ( t1 ) ? spanstart [t1 ] : 0 , x - 1 );
168184 t1 ++ ;
169185 }
170186 while (b1 > b2 && b1 >= t1 )
171187 {
172- r_map_plane (b1 , spanstart [b1 ], x - 1 );
188+ r_map_plane (b1 , r_row_in_range ( b1 ) ? spanstart [b1 ] : 0 , x - 1 );
173189 b1 -- ;
174190 }
175191
176192 while (t2 < t1 && t2 <= b2 )
177193 {
178- spanstart [t2 ] = x ;
194+ if (r_row_in_range (t2 ))
195+ {
196+ spanstart [t2 ] = x ;
197+ }
198+
179199 t2 ++ ;
180200 }
181201 while (b2 > b1 && b2 >= t2 )
182202 {
183- spanstart [b2 ] = x ;
203+ if (r_row_in_range (b2 ))
204+ {
205+ spanstart [b2 ] = x ;
206+ }
207+
184208 b2 -- ;
185209 }
186210}
@@ -314,13 +338,15 @@ visplane_t *r_check_plane(visplane_t *pl, int start, int stop)
314338
315339 /* make a new visplane */
316340
341+ if (lastvisplane - visplanes == CONFIG_GAMES_NXDOOM_MAXVISPLANES )
342+ {
343+ i_error ("r_check_plane: no more visplanes" );
344+ }
345+
317346 lastvisplane -> height = pl -> height ;
318347 lastvisplane -> picnum = pl -> picnum ;
319348 lastvisplane -> lightlevel = pl -> lightlevel ;
320349
321- if (lastvisplane - visplanes == CONFIG_GAMES_NXDOOM_MAXVISPLANES )
322- i_error ("r_check_plane: no more visplanes" );
323-
324350 pl = lastvisplane ++ ;
325351 pl -> minx = start ;
326352 pl -> maxx = stop ;
0 commit comments