309 |
|
} |
310 |
|
} else { /* read binary file */ |
311 |
|
if (sizeof(COLOR) == cm_elem_size[dtype]) { |
312 |
< |
int nread = 0; |
312 |
> |
size_t nread = 0; |
313 |
|
do { /* read all we can */ |
314 |
|
nread += getbinary(cm->cmem + 3*nread, |
315 |
|
sizeof(COLOR), |
316 |
< |
cm->nrows*cm->ncols - nread, |
316 |
> |
(size_t)cm->nrows*cm->ncols - nread, |
317 |
|
fp); |
318 |
|
if (nrows <= 0) { /* unknown length */ |
319 |
< |
if (nread == cm->nrows*cm->ncols) |
319 |
> |
if (nread == (size_t)cm->nrows*cm->ncols) |
320 |
|
/* need more space? */ |
321 |
|
cm = cm_resize(cm, cm->nrows+ROWINC); |
322 |
|
else if (nread && !(nread % cm->ncols)) |
324 |
|
cm = cm_resize(cm, nread/cm->ncols); |
325 |
|
else /* ended mid-row */ |
326 |
|
goto EOFerror; |
327 |
< |
} else if (nread < cm->nrows*cm->ncols) |
327 |
> |
} else if (nread < (size_t)cm->nrows*cm->ncols) |
328 |
|
goto EOFerror; |
329 |
< |
} while (nread < cm->nrows*cm->ncols); |
329 |
> |
} while (nread < (size_t)cm->nrows*cm->ncols); |
330 |
|
|
331 |
|
if (swap) { |
332 |
|
if (sizeof(COLORV) == 4) |
333 |
|
swap32((char *)cm->cmem, |
334 |
< |
3*cm->nrows*cm->ncols); |
334 |
> |
3*(size_t)cm->nrows*cm->ncols); |
335 |
|
else /* sizeof(COLORV) == 8 */ |
336 |
|
swap64((char *)cm->cmem, |
337 |
< |
3*cm->nrows*cm->ncols); |
337 |
> |
3*(size_t)cm->nrows*cm->ncols); |
338 |
|
} |
339 |
|
} else if (dtype == DTdouble) { |
340 |
|
double dc[3]; /* load from double */ |
341 |
|
COLORV *cvp = cm->cmem; |
342 |
< |
int n = nrows*ncols; |
342 |
> |
size_t n = (size_t)nrows*ncols; |
343 |
|
|
344 |
|
if (n <= 0) |
345 |
|
goto not_handled; |
353 |
|
} else /* dtype == DTfloat */ { |
354 |
|
float fc[3]; /* load from float */ |
355 |
|
COLORV *cvp = cm->cmem; |
356 |
< |
int n = nrows*ncols; |
356 |
> |
size_t n = (size_t)nrows*ncols; |
357 |
|
|
358 |
|
if (n <= 0) |
359 |
|
goto not_handled; |