ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/readoct.c
(Generate patch)

Comparing ray/src/common/readoct.c (file contents):
Revision 1.12 by greg, Thu Apr 18 13:01:28 1991 UTC vs.
Revision 2.1 by greg, Tue Nov 12 16:55:01 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 22 | Line 22 | extern double  atof();
22   static double  getflt();
23   static long  getint();
24   static char  *getstr();
25 + static int  getobj(), octerror();
26   static OCTREE  getfullnode(), gettree();
27  
28   static char  *infn;                     /* input file name */
29   static FILE  *infp;                     /* input file stream */
30 + static int  objsize;                    /* size of stored OBJECT's */
31   static OBJECT  objorig;                 /* zeroeth object */
32   static short  otypmap[NUMOTYPE+8];      /* object type map */
33  
# Line 42 | Line 44 | char  *ofn[];
44          int  nf;
45          OBJECT  fnobjects;
46          register int  i;
47 +        long  m;
48          
49          if (fname == NULL) {
50                  infn = "standard input";
# Line 58 | Line 61 | char  *ofn[];
61          if (checkheader(infp, OCTFMT, load&IO_INFO ? stdout : NULL) < 0)
62                  octerror(USER, "not an octree");
63                                          /* check format */
64 <        if (getint(2) != OCTMAGIC)
64 >        if ((objsize = getint(2)-OCTMAGIC) <= 0 ||
65 >                        objsize > MAXOBJSIZ || objsize > sizeof(long))
66                  octerror(USER, "incompatible octree format");
67                                          /* get boundaries */
68          if (load & IO_BOUNDS) {
# Line 81 | Line 85 | char  *ofn[];
85          if (load & IO_FILES)
86                  ofn[nf] = NULL;
87                                          /* get number of objects */
88 <        fnobjects = getint(sizeof(OBJECT));
88 >        fnobjects = m = getint(objsize);
89 >        if (fnobjects != m)
90 >                octerror(USER, "too many objects");
91  
92          if (load & IO_TREE) {
93                                                  /* get the octree */
# Line 96 | Line 102 | char  *ofn[];
102                                  }
103                          while (getobj() != OVOID)
104                                  ;
105 +                } else if (load & IO_SCENE) {           /* consistency checks */
106 +                                                /* check object count */
107 +                        if (nobjects != objorig+fnobjects)
108 +                                octerror(USER, "bad object count; octree stale?");
109 +                                                /* check for non-surfaces */
110 +                        if (nonsurfinset(objorig, fnobjects))
111 +                                octerror(USER, "non-surface in set; octree stale?");
112                  }
113          }
114          fclose(infp);
102                                        /* consistency checks */
103        if (load & IO_SCENE) {
104                                        /* check object count */
105                if (nobjects != objorig+fnobjects)
106                        octerror(USER, "bad object count; octree stale?");
107                                        /* check for non-surfaces */
108                if (nonsurfinset(objorig, fnobjects))
109                        octerror(USER, "non-surface in set; octree stale?");
110        }
115          return(nf);
116   }
117  
# Line 133 | Line 137 | getfullnode()                  /* get a set, return fullnode */
137   {
138          OBJECT  set[MAXSET+1];
139          register int  i;
140 +        register long  m;
141  
142 <        set[0] = getint(sizeof(OBJECT));
138 <        if (set[0] > MAXSET)
142 >        if ((set[0] = getint(objsize)) > MAXSET)
143                  octerror(USER, "bad set in getfullnode");
144 <        for (i = 1; i <= set[0]; i++)
145 <                set[i] = getint(sizeof(OBJECT)) + objorig;
144 >        for (i = 1; i <= set[0]; i++) {
145 >                m = getint(objsize) + objorig;
146 >                if ((set[i] = m) != m)
147 >                        octerror(USER, "too many objects");
148 >        }
149          return(fullnode(set));
150   }      
151  
# Line 207 | Line 214 | getobj()                               /* get next object */
214          char  sbuf[MAXSTR];
215          int  obj;
216          register int  i;
217 +        register long  m;
218          register OBJREC  *objp;
219  
220          i = getint(1);
# Line 217 | Line 225 | getobj()                               /* get next object */
225          objp = objptr(obj);
226          if ((objp->otype = otypmap[i]) < 0)
227                  octerror(USER, "reference to unknown type");
228 <        if ((objp->omod = getint(sizeof(OBJECT))) != OVOID)
229 <                objp->omod += objorig;
228 >        if ((m = getint(objsize)) != OVOID) {
229 >                m += objorig;
230 >                if ((OBJECT)m != m)
231 >                        octerror(USER, "too many objects");
232 >        }
233 >        objp->omod = m;
234          objp->oname = savqstr(getstr(sbuf));
235          if (objp->oargs.nsargs = getint(2)) {
236                  objp->oargs.sarg = (char **)bmalloc
# Line 241 | Line 253 | getobj()                               /* get next object */
253                  objp->oargs.iarg = NULL;
254   #endif
255          if (objp->oargs.nfargs = getint(2)) {
256 <                objp->oargs.farg = (double *)bmalloc
257 <                                (objp->oargs.nfargs*sizeof(double));
256 >                objp->oargs.farg = (FLOAT *)bmalloc
257 >                                (objp->oargs.nfargs*sizeof(FLOAT));
258                  if (objp->oargs.farg == NULL)
259                          goto memerr;
260                  for (i = 0; i < objp->oargs.nfargs; i++)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines