[x265] [PATCH] cli: fix warnings an linux

gopu at multicorewareinc.com gopu at multicorewareinc.com
Thu Nov 13 07:10:03 CET 2014


# HG changeset patch
# User Gopu Govindaswamy <gopu at multicorewareinc.com>
# Date 1415858987 -19800
#      Thu Nov 13 11:39:47 2014 +0530
# Node ID 2e30a7929ebd85c8ebede93cd0c41797bdf36ba0
# Parent  18aefbde72ab2dfaa0d4edeea7fd0ab4f9a09f9c
cli: fix warnings an linux

diff -r 18aefbde72ab -r 2e30a7929ebd source/x265.cpp
--- a/source/x265.cpp	Wed Nov 12 17:17:56 2014 -0600
+++ b/source/x265.cpp	Thu Nov 13 11:39:47 2014 +0530
@@ -808,7 +808,12 @@
     if (!paramBuf)
         return false;
 
-    fread(paramBuf, 1, MAXPARAMSIZE, this->analysisFile);
+    if (fread(paramBuf, 1, MAXPARAMSIZE, this->analysisFile) != MAXPARAMSIZE)
+    {
+        x265_log(NULL,X265_LOG_ERROR, "Error reading analysis data file for validataFanout\n");
+        X265_FREE(paramBuf);
+        return false;
+    }
 
     /* check whether fanout options are compatible */
     if (strncmp(paramBuf, "#options:", 9))
@@ -869,14 +874,23 @@
 
 void CLIOptions::readAnalysisFile(x265_picture* pic, x265_param* p)
 {
+
+#define FREAD(val, size, readSize, fileOffset)\
+    if (fread(val, size, readSize, fileOffset) != readSize)\
+    {\
+        x265_log(NULL, X265_LOG_ERROR, "Error reading analysis data\n");\
+        x265_free_analysis_data(pic);\
+        return;\
+    }\
+
     int poc, width, height;
     uint32_t numPart, numCU;
-    fread(&width, sizeof(int), 1, this->analysisFile);
-    fread(&height, sizeof(int), 1, this->analysisFile);
-    fread(&poc, sizeof(int), 1, this->analysisFile);
-    fread(&pic->sliceType, sizeof(int), 1, this->analysisFile);
-    fread(&numCU, sizeof(int), 1, this->analysisFile);
-    fread(&numPart, sizeof(int), 1, this->analysisFile);
+    FREAD(&width, sizeof(int), 1, this->analysisFile);
+    FREAD(&height, sizeof(int), 1, this->analysisFile);
+    FREAD(&poc, sizeof(int), 1, this->analysisFile);
+    FREAD(&pic->sliceType, sizeof(int), 1, this->analysisFile);
+    FREAD(&numCU, sizeof(int), 1, this->analysisFile);
+    FREAD(&numPart, sizeof(int), 1, this->analysisFile);
 
     if (width != p->sourceWidth || height != p->sourceHeight)
     {
@@ -892,33 +906,42 @@
         return;
     }
 
-    fread(pic->analysisData.intraData->depth,
+    FREAD(pic->analysisData.intraData->depth,
         sizeof(uint8_t), pic->analysisData.numPartitions * pic->analysisData.numCUsInFrame, this->analysisFile);
-    fread(pic->analysisData.intraData->modes,
+    FREAD(pic->analysisData.intraData->modes,
         sizeof(uint8_t), pic->analysisData.numPartitions * pic->analysisData.numCUsInFrame, this->analysisFile);
-    fread(pic->analysisData.intraData->partSizes,
+    FREAD(pic->analysisData.intraData->partSizes,
         sizeof(char), pic->analysisData.numPartitions * pic->analysisData.numCUsInFrame, this->analysisFile);
-    fread(pic->analysisData.interData, sizeof(x265_inter_data), pic->analysisData.numCUsInFrame * (X265_MAX_PRED_MODE_PER_CU), this->analysisFile);
+    FREAD(pic->analysisData.interData, sizeof(x265_inter_data), pic->analysisData.numCUsInFrame * (X265_MAX_PRED_MODE_PER_CU), this->analysisFile);
 }
 
 void CLIOptions::writeAnalysisFile(x265_picture* pic, x265_param *p)
 {
+
+#define FWRITE(val, size, writeSize, fileOffset)\
+    if (fwrite(val, size, writeSize, fileOffset) < writeSize)\
+    {\
+        x265_log(NULL, X265_LOG_ERROR, "Error writing analysis data\n");\
+        x265_free_analysis_data(pic);\
+        return;\
+    }\
+
     uint64_t seekTo = pic->poc * this->analysisRecordSize + this->analysisHeaderSize;
     fseeko(this->analysisFile, seekTo, SEEK_SET);
-    fwrite(&p->sourceWidth, sizeof(int), 1, this->analysisFile);
-    fwrite(&p->sourceHeight, sizeof(int), 1, this->analysisFile);
-    fwrite(&pic->poc, sizeof(int), 1, this->analysisFile);
-    fwrite(&pic->sliceType, sizeof(int), 1, this->analysisFile);
-    fwrite(&pic->analysisData.numCUsInFrame, sizeof(int), 1, this->analysisFile);
-    fwrite(&pic->analysisData.numPartitions, sizeof(int), 1, this->analysisFile);
+    FWRITE(&p->sourceWidth, sizeof(int), 1, this->analysisFile);
+    FWRITE(&p->sourceHeight, sizeof(int), 1, this->analysisFile);
+    FWRITE(&pic->poc, sizeof(int), 1, this->analysisFile);
+    FWRITE(&pic->sliceType, sizeof(int), 1, this->analysisFile);
+    FWRITE(&pic->analysisData.numCUsInFrame, sizeof(int), 1, this->analysisFile);
+    FWRITE(&pic->analysisData.numPartitions, sizeof(int), 1, this->analysisFile);
 
-    fwrite(pic->analysisData.intraData->depth,
+    FWRITE(pic->analysisData.intraData->depth,
         sizeof(uint8_t), pic->analysisData.numPartitions * pic->analysisData.numCUsInFrame, this->analysisFile);
-    fwrite(pic->analysisData.intraData->modes,
+    FWRITE(pic->analysisData.intraData->modes,
         sizeof(uint8_t), pic->analysisData.numPartitions * pic->analysisData.numCUsInFrame, this->analysisFile);
-    fwrite(pic->analysisData.intraData->partSizes,
+    FWRITE(pic->analysisData.intraData->partSizes,
         sizeof(char), pic->analysisData.numPartitions * pic->analysisData.numCUsInFrame, this->analysisFile);
-    fwrite(pic->analysisData.interData, sizeof(x265_inter_data), pic->analysisData.numCUsInFrame * X265_MAX_PRED_MODE_PER_CU, this->analysisFile);
+    FWRITE(pic->analysisData.interData, sizeof(x265_inter_data), pic->analysisData.numCUsInFrame * X265_MAX_PRED_MODE_PER_CU, this->analysisFile);
 }
 
 bool CLIOptions::parseQPFile(x265_picture &pic_org)


More information about the x265-devel mailing list