[comp.sources.bugs] robots2

oleg@ncoast.UUCP (08/22/87)

While playing the new robots game (posted recently to comp.sources.games),
I discovered that the game would coredump when checking "safety" of a teleport
destination.  

Not having much time to analyze the game, I put in a check for the validity of
the examined location before a call to "move()" and it seemed to have fixed 
the problem.  I am not sure if this is REALLY a correct fix, however, and there
may be more places where bounds checking needs to be done.  Just goes to show:
always compile with "-g" and never strip your executables until you are REALLY
sure... :-)  


*** good.c.orig	Thu Aug 13 15:02:21 1987
--- good.c	Thu Aug 13 15:03:43 1987
***************
*** 90,95
  				/* we are 2 steps out */
  				if( blocked(ty, tx, y, x))
  					continue;
  				move(ty+y,tx+x);
  				if ( abs(x) == 2 && abs(y) == 2
  							&& inch() == FROBOT){

--- 90,99 -----
  				/* we are 2 steps out */
  				if( blocked(ty, tx, y, x))
  					continue;
+ 				if ((ty+y) < 0 || (tx+x) < 0 || (ty+y) > VERT
+ 					|| (tx+x) > HORIZ) 
+ 					continue;
+ 
  				move(ty+y,tx+x);
  				if ( abs(x) == 2 && abs(y) == 2
  							&& inch() == FROBOT){



-- 
Oleg Kiselev  --  oleg@quad1.quad.com -- {...!psivax|seismo!gould}!quad1!oleg

DISCLAIMER: All grammatical and spelling errors are inserted deliberately to
test the software I am developing.  In fact, that is the only reason I am 
posting. Yeah, that's the ticket! All my postings are just test data! Yeah!!