--- ray/src/gen/genprism.c 1989/02/02 11:16:28 1.1 +++ ray/src/gen/genprism.c 1996/02/22 14:38:51 2.5 @@ -10,16 +10,20 @@ static char SCCSid[] = "$SunId$ LBL"; * command line or from a file. Their order together * with the extrude direction will determine surface * orientation. - * - * 8/24/87 */ #include +#include + #include #define MAXVERT 1024 /* maximum # vertices */ +#ifdef DCL_ATOF +extern double atof(); +#endif + char *pmtype; /* material type */ char *pname; /* name */ @@ -36,7 +40,6 @@ main(argc, argv) int argc; char **argv; { - double atof(); int an; if (argc < 4) @@ -50,6 +53,11 @@ char **argv; an = 4; } else if (isdigit(argv[3][0])) { nverts = atoi(argv[3]); + if (nverts > MAXVERT) { + fprintf(stderr, "%s: too many vertices (%d limit)\n", + argv[0], MAXVERT); + exit(1); + } if (argc-3 < 2*nverts) goto userr; for (an = 0; an < nverts; an++) { @@ -102,18 +110,23 @@ userr: readverts(fname) /* read vertices from a file */ -FILE *fname; +char *fname; { FILE *fp; - if (fname == NULL) + if (fname == NULL) { fp = stdin; - else if ((fp = fopen(fname, "r")) == NULL) { + fname = ""; + } else if ((fp = fopen(fname, "r")) == NULL) { fprintf(stderr, "%s: cannot open\n", fname); exit(1); } while (fscanf(fp, "%lf %lf", &vert[nverts][0], &vert[nverts][1]) == 2) - nverts++; + if (++nverts >= MAXVERT) { + fprintf(stderr, "%s: too many vertices (%d limit)\n", + fname, MAXVERT-1); + exit(1); + } fclose(fp); }