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

Comparing ray/src/gen/genprism.c (file contents):
Revision 1.2 by greg, Tue Mar 14 15:08:35 1989 UTC vs.
Revision 2.5 by greg, Thu Feb 22 14:38:51 1996 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10   *              command line or from a file.  Their order together
11   *              with the extrude direction will determine surface
12   *              orientation.
13 *
14 *     8/24/87
13   */
14  
15   #include  <stdio.h>
16  
17 + #include  <math.h>
18 +
19   #include  <ctype.h>
20  
21   #define  MAXVERT        1024            /* maximum # vertices */
22  
23 + #ifdef  DCL_ATOF
24 + extern double  atof();
25 + #endif
26 +
27   char  *pmtype;          /* material type */
28   char  *pname;           /* name */
29  
# Line 36 | Line 40 | main(argc, argv)
40   int  argc;
41   char  **argv;
42   {
39        double  atof();
43          int  an;
44          
45          if (argc < 4)
# Line 50 | Line 53 | char  **argv;
53                  an = 4;
54          } else if (isdigit(argv[3][0])) {
55                  nverts = atoi(argv[3]);
56 +                if (nverts > MAXVERT) {
57 +                        fprintf(stderr, "%s: too many vertices (%d limit)\n",
58 +                                        argv[0], MAXVERT);
59 +                        exit(1);
60 +                }
61                  if (argc-3 < 2*nverts)
62                          goto userr;
63                  for (an = 0; an < nverts; an++) {
# Line 106 | Line 114 | char  *fname;
114   {
115          FILE  *fp;
116  
117 <        if (fname == NULL)
117 >        if (fname == NULL) {
118                  fp = stdin;
119 <        else if ((fp = fopen(fname, "r")) == NULL) {
119 >                fname = "<stdin>";
120 >        } else if ((fp = fopen(fname, "r")) == NULL) {
121                  fprintf(stderr, "%s: cannot open\n", fname);
122                  exit(1);
123          }
124          while (fscanf(fp, "%lf %lf", &vert[nverts][0], &vert[nverts][1]) == 2)
125 <                nverts++;
125 >                if (++nverts >= MAXVERT) {
126 >                        fprintf(stderr, "%s: too many vertices (%d limit)\n",
127 >                                        fname, MAXVERT-1);
128 >                        exit(1);
129 >                }
130          fclose(fp);
131   }
132  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines