--- ray/src/gen/genprism.c 1991/12/19 15:08:51 2.2 +++ ray/src/gen/genprism.c 1996/02/22 14:38:51 2.5 @@ -10,17 +10,17 @@ 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 */ -#ifndef atof +#ifdef DCL_ATOF extern double atof(); #endif @@ -53,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++) { @@ -109,14 +114,19 @@ 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); }