--- ray/src/common/readoct.c 1989/03/22 09:53:46 1.4 +++ ray/src/common/readoct.c 1989/09/19 13:40:48 1.6 @@ -59,7 +59,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++) @@ -139,16 +139,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"); }