[trunk] Properly store and use value returned by fread. Also invert nmemb and size...
authorMathieu Malaterre <mathieu.malaterre@gmail.com>
Wed, 26 Feb 2014 09:40:19 +0000 (09:40 +0000)
committerMathieu Malaterre <mathieu.malaterre@gmail.com>
Wed, 26 Feb 2014 09:40:19 +0000 (09:40 +0000)
Fixes issue 262

src/bin/jp2/opj_compress.c

index 7b1c947181691d541dca4f372f266021683f7d99..da89e512bf4b3a57f9cf3248c4b8feac4c5dd409 100644 (file)
@@ -930,7 +930,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
             float *lCurrentDoublePtr;
             float *lSpace;
             int *l_int_ptr;
-            int lNbComp = 0, lTotalComp, lMctComp, i, lStrLen;
+            int lNbComp = 0, lTotalComp, lMctComp, i, lStrLen, lStrFread;
 
             /* Open file */
             FILE * lFile = fopen(lFilename,"r");
@@ -943,8 +943,9 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
             lStrLen = ftell(lFile);
             fseek(lFile,0,SEEK_SET);
             lMatrix = (char *) malloc(lStrLen + 1);
-            fread(lMatrix, lStrLen, 1, lFile);
+            lStrFread = fread(lMatrix, 1, lStrLen, lFile);
             fclose(lFile);
+            if( lStrLen != lStrFread ) return 1;
 
             lMatrix[lStrLen] = 0;
             lCurrentPtr = lMatrix;