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/trunk@1060 632fc199-4ca6-4c93-a231-07263d6284db
diff --git a/djpeg.c b/djpeg.c
index e4e8a62..589c580 100644
--- a/djpeg.c
+++ b/djpeg.c
@@ -566,7 +566,7 @@
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]);
diff --git a/tjbench.c b/tjbench.c
index b2ef8d6..58ed147 100644
--- a/tjbench.c
+++ b/tjbench.c
@@ -491,7 +491,7 @@
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");