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

Comparing ray/src/util/rcrop.c (file contents):
Revision 1.14 by greg, Tue Nov 21 02:06:14 2023 UTC vs.
Revision 1.17 by greg, Wed Jun 5 17:30:56 2024 UTC

# Line 97 | Line 97 | binary_copyf(FILE *fp, int asize)
97          int             y;
98                                          /* check if fseek() useful */
99          if (skip_len > skip_thresh &&
100 <                        fseek(fp, (rmin*width + cmin)*elsiz, SEEK_CUR) == 0) {
100 >                        fseek(fp, ((long)rmin*width + cmin)*elsiz, SEEK_CUR) == 0) {
101 >                int     fd;
102                  off_t   curpos;
103                  buf = (char *)malloc(ncols*elsiz);
104                  if (!buf)
# Line 115 | Line 116 | binary_copyf(FILE *fp, int asize)
116                          }
117                  }
118   #else
119 +                fd = fileno(fp);
120                  curpos = ftello(fp);
121                  for (y = nrows; y-- > 0; curpos += width*elsiz) {
122 <                        if (pread(fileno(fp), buf, ncols*elsiz,
122 >                        if (pread(fd, buf, ncols*elsiz,
123                                                  curpos) != ncols*elsiz)
124                                  goto readerr;
125                          if (putbinary(buf, elsiz, ncols, stdout) != ncols)
# Line 134 | Line 136 | binary_copyf(FILE *fp, int asize)
136                  goto memerr;
137                                          /* skip rows as requested */
138          if (skip_len > skip_thresh ||
139 <                        (rmin && fseek(fp, rmin*width*elsiz, SEEK_CUR) < 0))
139 >                        (rmin && fseek(fp, (long)rmin*width*elsiz, SEEK_CUR) < 0))
140                  for (y = 0; y < rmin; y++)
141                          if (getbinary(buf, elsiz, width, fp) != width)
142                                  goto readerr;
# Line 163 | Line 165 | memerr:
165  
166   /* Read (and copy) specified number of white-space-separated words */
167   static int
168 < readwords(FILE *finp, int nwords, FILE *fout)
168 > readwords(FILE *finp, long nwords, FILE *fout)
169   {
170          while (nwords-- > 0) {
171                  int     c;
# Line 192 | Line 194 | ascii_copyf(FILE *fp)
194          SET_FILE_TEXT(fp);              /* started as binary */
195          SET_FILE_TEXT(stdout);
196                                          /* skip rows as requested */
197 <        if (readwords(fp, rmin*width*ncomp, NULL) < 0)
197 >        if (readwords(fp, (long)rmin*width*ncomp, NULL) < 0)
198                  goto io_err;
199          for (y = 0; y < nrows; y++) {   /* copy part */
200                  if (readwords(fp, cmin*ncomp, NULL) < 0)
# Line 269 | Line 271 | main(int argc, char *argv[])
271          cmin = atoi(argv[2]);
272          nrows = atoi(argv[3]);
273          ncols = atoi(argv[4]);
274 <        if ((rmin < 0) | (cmin < 0) | (nrows < 0) | (ncols < 0))
274 >        if ((rmin < 0) | (cmin < 0))
275                  goto usage;
276          if (argc <= 5)
277                  SET_FILE_BINARY(fp);
# Line 301 | Line 303 | main(int argc, char *argv[])
303                  fputs(": missing input dimensions\n", stderr);
304                  return(1);
305          }
306 <        if (!nrows)
307 <                nrows = numscans(&res) - rmin;
308 <        if (!ncols)
309 <                ncols = scanlen(&res) - cmin;
306 >        if (nrows <= 0 )
307 >                nrows += numscans(&res) - rmin;
308 >        if (ncols <= 0)
309 >                ncols += scanlen(&res) - cmin;
310          if ((nrows <= 0) | (ncols <= 0) |
311                          (rmin+nrows > numscans(&res)) |
312                          (cmin+ncols > scanlen(&res))) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines