[x265-commits] [x265] Fix problems found by clang static analyzser in Xcode

Steve Borho steve at borho.org
Fri Feb 7 04:21:23 CET 2014


details:   http://hg.videolan.org/x265/rev/1a68f0dd9acb
branches:  
changeset: 6044:1a68f0dd9acb
user:      Steve Borho <steve at borho.org>
date:      Thu Feb 06 21:09:04 2014 -0600
description:
Fix problems found by clang static analyzser in Xcode

These were mainly stores that were never read

diffstat:

 source/Lib/TLibCommon/TComDataCU.cpp                |  15 ++++++---------
 source/Lib/TLibCommon/TComLoopFilter.cpp            |   3 ---
 source/Lib/TLibCommon/TComPrediction.cpp            |   2 --
 source/Lib/TLibCommon/TComTrQuant.cpp               |   4 +---
 source/Lib/TLibEncoder/TEncCu.cpp                   |   7 -------
 source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp |   6 ++----
 source/Lib/TLibEncoder/TEncSearch.cpp               |   6 ------
 source/common/primitives.cpp                        |   2 +-
 source/encoder/encoder.cpp                          |   4 ++--
 source/encoder/ratecontrol.cpp                      |   3 +--
 source/encoder/slicetype.cpp                        |   1 -
 source/encoder/weightPrediction.cpp                 |   2 +-
 source/x265.cpp                                     |   4 ++--
 13 files changed, 16 insertions(+), 43 deletions(-)

diffs (truncated from 307 to 300 lines):

diff -r c54271b906da -r 1a68f0dd9acb source/Lib/TLibCommon/TComDataCU.cpp
--- a/source/Lib/TLibCommon/TComDataCU.cpp	Thu Feb 06 18:59:19 2014 -0600
+++ b/source/Lib/TLibCommon/TComDataCU.cpp	Thu Feb 06 21:09:04 2014 -0600
@@ -2096,7 +2096,7 @@ void TComDataCU::getInterMergeCandidates
     {
         //>> MTK colocated-RightBottom
         uint32_t partIdxRB;
-        int lcuIdx = getAddr();
+        int lcuIdx;
 
         deriveRightBottomIdx(puIdx, partIdxRB);
 
@@ -2392,7 +2392,7 @@ void TComDataCU::fillMvpCand(uint32_t pa
         bAdded = xAddMVPCandOrder(info, picList, refIdx, partIdxLB, MD_BELOW_LEFT);
         if (!bAdded)
         {
-            bAdded = xAddMVPCandOrder(info, picList, refIdx, partIdxLB, MD_LEFT);
+            xAddMVPCandOrder(info, picList, refIdx, partIdxLB, MD_LEFT);
         }
     }
     // Above predictor search
@@ -2405,7 +2405,7 @@ void TComDataCU::fillMvpCand(uint32_t pa
 
     if (!bAdded)
     {
-        bAdded = xAddMVPCand(info, picList, refIdx, partIdxLT, MD_ABOVE_LEFT);
+        xAddMVPCand(info, picList, refIdx, partIdxLT, MD_ABOVE_LEFT);
     }
     bAdded = bAddedSmvp;
     if (info->m_num == 2) bAdded = true;
@@ -2420,7 +2420,7 @@ void TComDataCU::fillMvpCand(uint32_t pa
 
         if (!bAdded)
         {
-            bAdded = xAddMVPCandOrder(info, picList, refIdx, partIdxLT, MD_ABOVE_LEFT);
+            xAddMVPCandOrder(info, picList, refIdx, partIdxLT, MD_ABOVE_LEFT);
         }
     }
 
@@ -2440,7 +2440,7 @@ void TComDataCU::fillMvpCand(uint32_t pa
         uint32_t partIdxRB;
         uint32_t absPartIdx;
         uint32_t absPartAddr;
-        int lcuIdx = getAddr();
+        int lcuIdx;
 
         deriveRightBottomIdx(partIdx, partIdxRB);
         absPartAddr = m_absIdxInLCU + partAddr;
@@ -2537,9 +2537,7 @@ void TComDataCU::clipMv(MV& outMV)
 
 uint32_t TComDataCU::getIntraSizeIdx(uint32_t absPartIdx)
 {
-    uint32_t shift = ((m_trIdx[absPartIdx] == 0) && (m_partSizes[absPartIdx] == SIZE_NxN)) ? m_trIdx[absPartIdx] + 1 : m_trIdx[absPartIdx];
-
-    shift = (m_partSizes[absPartIdx] == SIZE_NxN ? 1 : 0);
+    uint32_t shift = (m_partSizes[absPartIdx] == SIZE_NxN ? 1 : 0);
 
     UChar width = m_width[absPartIdx] >> shift;
     uint32_t  cnt = 0;
@@ -2822,7 +2820,6 @@ bool TComDataCU::xGetColMVP(int picList,
         return false;
     }
     curPOC = m_slice->getPOC();
-    curRefPOC = m_slice->getRefPic(picList, outRefIdx)->getPOC();
     colPOC = colCU->getSlice()->getPOC();
 
     if (colCU->isIntra(absPartAddr))
diff -r c54271b906da -r 1a68f0dd9acb source/Lib/TLibCommon/TComLoopFilter.cpp
--- a/source/Lib/TLibCommon/TComLoopFilter.cpp	Thu Feb 06 18:59:19 2014 -0600
+++ b/source/Lib/TLibCommon/TComLoopFilter.cpp	Thu Feb 06 21:09:04 2014 -0600
@@ -463,7 +463,6 @@ void TComLoopFilter::xGetBoundaryStrengt
 
                 if (((refP0 == refQ0) && (refP1 == refQ1)) || ((refP0 == refQ1) && (refP1 == refQ0)))
                 {
-                    bs = 0;
                     if (refP0 != refP1) // Different L0 & L1
                     {
                         if (refP0 == refQ0)
@@ -694,8 +693,6 @@ void TComLoopFilter::xEdgeFilterChroma(T
 
     for (uint32_t idx = 0; idx < numParts; idx++)
     {
-        bs = 0;
-
         bsAbsIdx = xCalcBsIdx(cu, absZOrderIdx, dir, edge, idx);
         bs = m_blockingStrength[dir][bsAbsIdx];
 
diff -r c54271b906da -r 1a68f0dd9acb source/Lib/TLibCommon/TComPrediction.cpp
--- a/source/Lib/TLibCommon/TComPrediction.cpp	Thu Feb 06 18:59:19 2014 -0600
+++ b/source/Lib/TLibCommon/TComPrediction.cpp	Thu Feb 06 21:09:04 2014 -0600
@@ -131,7 +131,6 @@ void TComPrediction::predIntraLumaAng(ui
 
     int log2BlkSize = g_convertToBit[size] + 2;
 
-    Pel *src = m_predBuf;
     assert(log2BlkSize >= 2 && log2BlkSize < 7);
     int diff = std::min<int>(abs((int)dirMode - HOR_IDX), abs((int)dirMode - VER_IDX));
     UChar filterIdx = diff > intraFilterThreshold[log2BlkSize - 2] ? 1 : 0;
@@ -148,7 +147,6 @@ void TComPrediction::predIntraLumaAng(ui
 
     if (filterIdx)
     {
-        src += ADI_BUF_STRIDE * (2 * size + 1);
         refLft = refLeftFlt + size - 1;
         refAbv = refAboveFlt + size - 1;
     }
diff -r c54271b906da -r 1a68f0dd9acb source/Lib/TLibCommon/TComTrQuant.cpp
--- a/source/Lib/TLibCommon/TComTrQuant.cpp	Thu Feb 06 18:59:19 2014 -0600
+++ b/source/Lib/TLibCommon/TComTrQuant.cpp	Thu Feb 06 21:09:04 2014 -0600
@@ -469,18 +469,16 @@ void TComTrQuant::xITransformSkip(int32_
     assert(width == height);
     uint32_t log2TrSize = g_convertToBit[width] + 2;
     int  shift = MAX_TR_DYNAMIC_RANGE - X265_DEPTH - log2TrSize;
-    uint32_t transformSkipShift;
     int  j, k;
     if (shift > 0)
     {
         assert(width == height);
-        transformSkipShift = shift;
         primitives.cvt32to16_shr(residual, coef, stride, shift, width);
     }
     else
     {
         //The case when X265_DEPTH >= 13
-        transformSkipShift = -shift;
+        uint32_t transformSkipShift = -shift;
         for (j = 0; j < height; j++)
         {
             for (k = 0; k < width; k++)
diff -r c54271b906da -r 1a68f0dd9acb source/Lib/TLibEncoder/TEncCu.cpp
--- a/source/Lib/TLibEncoder/TEncCu.cpp	Thu Feb 06 18:59:19 2014 -0600
+++ b/source/Lib/TLibEncoder/TEncCu.cpp	Thu Feb 06 21:09:04 2014 -0600
@@ -1097,13 +1097,6 @@ void TEncCu::finishCU(TComDataCU* cu, ui
         numberOfWrittenBits = m_entropyCoder->getNumberOfWrittenBits();
     }
 
-    // Calculate slice end IF this CU puts us over slice bit size.
-    uint32_t granularitySize = cu->getPic()->getNumPartInCU();
-    int granularityEnd = ((cu->getSCUAddr() + absPartIdx) / granularitySize) * granularitySize;
-    if (granularityEnd <= 0)
-    {
-        granularityEnd += X265_MAX(granularitySize, (cu->getPic()->getNumPartInCU() >> (depth << 1)));
-    }
     if (granularityBoundary)
     {
         slice->setSliceBits((uint32_t)(slice->getSliceBits() + numberOfWrittenBits));
diff -r c54271b906da -r 1a68f0dd9acb source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
--- a/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	Thu Feb 06 18:59:19 2014 -0600
+++ b/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	Thu Feb 06 21:09:04 2014 -0600
@@ -145,8 +145,6 @@ void TEncSampleAdaptiveOffset::rdoSaoOne
         m_rdGoOnSbacCoder->load(m_rdSbacCoders[onePart->partLevel][CI_CURR_BEST]);
         m_rdGoOnSbacCoder->resetBits();
 
-        estDist = 0;
-
         if (typeIdx == -1)
         {
             for (int ry = onePart->startCUY; ry <= onePart->endCUY; ry++)
@@ -1085,8 +1083,8 @@ void TEncSampleAdaptiveOffset::calcSaoSt
     Pel* fenc;
     Pel* pRec;
     int stride;
-    int lcuHeight = pTmpSPS->getMaxCUHeight();
-    int lcuWidth  = pTmpSPS->getMaxCUWidth();
+    int lcuHeight;
+    int lcuWidth;
     uint32_t rPelX;
     uint32_t bPelY;
     int64_t* stats;
diff -r c54271b906da -r 1a68f0dd9acb source/Lib/TLibEncoder/TEncSearch.cpp
--- a/source/Lib/TLibEncoder/TEncSearch.cpp	Thu Feb 06 18:59:19 2014 -0600
+++ b/source/Lib/TLibEncoder/TEncSearch.cpp	Thu Feb 06 21:09:04 2014 -0600
@@ -839,7 +839,6 @@ void TEncSearch::xRecurIntraCodingQT(TCo
             m_rdGoOnSbacCoder->store(m_rdSbacCoders[fullDepth][CI_QT_TRAFO_ROOT]);
 
             //----- code luma block with given intra prediction mode and store Cbf-----
-            singleCost = 0;
             xIntraCodingLumaBlk(cu, trDepth, absPartIdx, fencYuv, predYuv, resiYuv, singleDistY);
             if (bCheckSplit)
             {
@@ -1998,7 +1997,6 @@ void TEncSearch::estIntraPredQT(TComData
                 bestPUMode  = origMode;
                 bestPUDistY = puDistY;
                 bestPUDistC = puDistC;
-                bestPUCost  = puCost;
 
                 xSetIntraResultQT(cu, initTrDepth, partOffset, bLumaOnly, reconYuv);
 
@@ -3121,8 +3119,6 @@ void TEncSearch::encodeResAndCalcRdInter
     }
     if (zeroCost < cost)
     {
-        cost       = zeroCost;
-        bits       = 0;
         distortion = zeroDistortion;
 
         const uint32_t qpartnum = cu->getPic()->getNumPartInCU() >> (cu->getDepth(0) << 1);
@@ -3159,7 +3155,6 @@ void TEncSearch::encodeResAndCalcRdInter
         }
 
         bestBits = bits;
-        bdist    = distortion;
         bcost    = cost;
         qpBest   = qp;
         m_rdGoOnSbacCoder->store(m_rdSbacCoders[cu->getDepth(0)][CI_TEMP_BEST]);
@@ -3877,7 +3872,6 @@ void TEncSearch::xEstimateResidualQT(TCo
 
             m_entropyCoder->resetBits();
             singleBitsU = 0;
-            singleBitsV = 0;
 
             if (absSumTransformSkipU)
             {
diff -r c54271b906da -r 1a68f0dd9acb source/common/primitives.cpp
--- a/source/common/primitives.cpp	Thu Feb 06 18:59:19 2014 -0600
+++ b/source/common/primitives.cpp	Thu Feb 06 21:09:04 2014 -0600
@@ -116,7 +116,7 @@ void x265_setup_primitives(x265_param *p
                 p += sprintf(p, " %s", x265::cpu_names[i].name);
         }
         if (!cpuid)
-            p += sprintf(p, " none!");
+            sprintf(p, " none!");
         x265_log(param, X265_LOG_INFO, "%s\n", buf);
     }
 
diff -r c54271b906da -r 1a68f0dd9acb source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Thu Feb 06 18:59:19 2014 -0600
+++ b/source/encoder/encoder.cpp	Thu Feb 06 21:09:04 2014 -0600
@@ -420,8 +420,8 @@ char* Encoder::statsString(EncStats& sta
     }
     if (param.bEnableSsim)
     {
-        len += sprintf(buffer + len, " SSIM Mean: %.6lf",
-                       stat.m_globalSsim / (double)stat.m_numPics);
+        sprintf(buffer + len, " SSIM Mean: %.6lf",
+                stat.m_globalSsim / (double)stat.m_numPics);
     }
     return buffer;
 }
diff -r c54271b906da -r 1a68f0dd9acb source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Thu Feb 06 18:59:19 2014 -0600
+++ b/source/encoder/ratecontrol.cpp	Thu Feb 06 21:09:04 2014 -0600
@@ -657,12 +657,11 @@ double RateControl::clipQscale(double q)
         {
             int nb = bframes;
             double bits = predictSize(&pred[sliceType], q, (double)lastSatd);
-            double pbbits = bits;
             double bbits = predictSize(&predBfromP, q * cfg->param.rc.pbFactor, (double)lastSatd);
             double space;
             if (bbits > bufferRate)
                 nb = 0;
-            pbbits = nb * bbits;
+            double pbbits = nb * bbits;
 
             space = bufferFill + (1 + nb) * bufferRate - bufferSize;
             if (pbbits < space)
diff -r c54271b906da -r 1a68f0dd9acb source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp	Thu Feb 06 18:59:19 2014 -0600
+++ b/source/encoder/slicetype.cpp	Thu Feb 06 21:09:04 2014 -0600
@@ -528,7 +528,6 @@ void Lookahead::slicetypeAnalyse(Lowres 
         }
 
         resetStart = bKeyframe ? 1 : 2;
-        numBFrames = 0;
     }
 
     if (cfg->param.rc.cuTree)
diff -r c54271b906da -r 1a68f0dd9acb source/encoder/weightPrediction.cpp
--- a/source/encoder/weightPrediction.cpp	Thu Feb 06 18:59:19 2014 -0600
+++ b/source/encoder/weightPrediction.cpp	Thu Feb 06 21:09:04 2014 -0600
@@ -364,7 +364,6 @@ bool WeightPrediction::checkDenom(int de
                             ioff = Clip3(-128, 127, ioff);
                         }
 
-                        s = 0;
                         SET_WEIGHT(w, 1, is, mindenom, ioff);
                         s = weightCost(m_inbuf, m_mcbuf, &w);
                         COPY4_IF_LT(minscore, s, minscale, is, minoff, ioff, found, 1);
@@ -415,6 +414,7 @@ bool WeightPrediction::checkDenom(int de
                     SET_WEIGHT(fw[1], 0, 1 << denom, denom, 0);
                     SET_WEIGHT(fw[2], 0, 1 << denom, denom, 0);
                     fullCheck -= check;
+                    /* TODO: this is wrong! we can't just exit here */
                     return false;
                 }
             }
diff -r c54271b906da -r 1a68f0dd9acb source/x265.cpp
--- a/source/x265.cpp	Thu Feb 06 18:59:19 2014 -0600
+++ b/source/x265.cpp	Thu Feb 06 21:09:04 2014 -0600
@@ -437,8 +437,6 @@ bool CLIOptions::parse(int argc, char **
             if (0) ;
             OPT("cpuid") cpuid = atoi(optarg);
             OPT("frames") this->framesToBeEncoded = (uint32_t)atoi(optarg);
-            OPT("preset") preset = optarg;
-            OPT("tune") tune = optarg;
             OPT("no-progress") this->bProgress = false;
             OPT("frame-skip") this->frameSkip = (uint32_t)atoi(optarg);
             OPT("output") bitstreamfn = optarg;
@@ -449,6 +447,8 @@ bool CLIOptions::parse(int argc, char **
             OPT("input-res") inputRes = optarg;


More information about the x265-commits mailing list