Fix a couple of issues with return value checking. JFREAD(), which wraps fread(), will never return -1. fread() will instead return 0 or a short object count if an error occurs, and ferror() will return 1 in that case. The second issue was that we were assigning the return value of ftell() to an unsigned long prior to checking the value, so the value would never be < 0 if an error occurred. It would instead be (unsigned long)-1.
git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/branches/1.3.x@1061 632fc199-4ca6-4c93-a231-07263d6284db
This commit is contained in:
2
djpeg.c
2
djpeg.c
@@ -566,7 +566,7 @@ main (int argc, char **argv)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
nbytes = JFREAD(input_file, &inbuffer[insize], INPUT_BUF_SIZE);
|
||||
if (nbytes < 0) {
|
||||
if (nbytes < INPUT_BUF_SIZE && ferror(input_file)) {
|
||||
if (file_index < argc)
|
||||
fprintf(stderr, "%s: can't read from %s\n", progname,
|
||||
argv[file_index]);
|
||||
|
||||
@@ -475,7 +475,7 @@ void dodecomptest(char *filename)
|
||||
|
||||
if((file=fopen(filename, "rb"))==NULL)
|
||||
_throwunix("opening file");
|
||||
if(fseek(file, 0, SEEK_END)<0 || (srcsize=ftell(file))<0)
|
||||
if(fseek(file, 0, SEEK_END)<0 || (srcsize=ftell(file))==(unsigned long)-1)
|
||||
_throwunix("determining file size");
|
||||
if((srcbuf=(unsigned char *)malloc(srcsize))==NULL)
|
||||
_throwunix("allocating memory");
|
||||
|
||||
Reference in New Issue
Block a user