--- ray/src/common/readoct.c 1989/03/21 15:54:45 1.3 +++ ray/src/common/readoct.c 1990/12/12 22:43:57 1.10 @@ -18,11 +18,11 @@ static char SCCSid[] = "$SunId$ LBL"; #include "otypes.h" -double atof(); -double getflt(); -long getint(); -char *getstr(); -OCTREE getfullnode(), gettree(); +extern double atof(); +static double getflt(); +static long getint(); +static char *getstr(); +static OCTREE getfullnode(), gettree(); static char *infn; /* input file name */ static FILE *infp; /* input file stream */ @@ -39,6 +39,7 @@ char *ofn[]; { char sbuf[128]; int nf; + OBJECT fnobjects; register int i; if (fname == NULL) { @@ -59,7 +60,7 @@ char *ofn[]; getheader(infp, NULL); /* check format */ if (getint(2) != OCTMAGIC) - octerror(USER, "bad octree"); + octerror(USER, "invalid octree format"); /* get boundaries */ if (load & IO_BOUNDS) { for (i = 0; i < 3; i++) @@ -80,6 +81,8 @@ char *ofn[]; } if (load & IO_FILES) ofn[nf] = NULL; + /* get number of objects */ + fnobjects = getint(sizeof(OBJECT)); if (load & IO_TREE) { /* get the octree */ @@ -97,6 +100,15 @@ char *ofn[]; } } fclose(infp); + /* consistency checks */ + if (load & IO_SCENE) { + /* check object count */ + if (nobjects != objorig+fnobjects) + octerror(USER, "bad object count; octree stale?"); + /* check for non-surfaces */ + if (nonsurfinset(objorig, fnobjects)) + octerror(USER, "non-surface in set; octree stale?"); + } return(nf); } @@ -139,16 +151,18 @@ register int siz; register int c; register long r; - c = getc(infp); - r = c&0x80 ? -1L : 0L; /* sign extend */ - ungetc(c, infp); - while (siz--) { + if ((c = getc(infp)) == EOF) + goto end_file; + r = 0x80&c ? -1<<8|c : c; /* sign extend */ + while (--siz > 0) { if ((c = getc(infp)) == EOF) - octerror(USER, "truncated octree"); + goto end_file; r <<= 8; r |= c; } return(r); +end_file: + octerror(USER, "truncated octree"); } @@ -159,7 +173,7 @@ getflt() /* get a floating point number */ double d; d = (double)getint(4)/0x7fffffff; - return(ldexp(d, getint(1))); /* sign extend */ + return(ldexp(d, (int)getint(1))); }