[x265] [PATCH] fix read uninitialize memory warning in Valgrind-3.10.0

Min Chen chenm003 at 163.com
Wed Nov 25 21:37:36 CET 2015


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1448483847 21600
# Node ID 64aa89a464aaccfa8098b25ec0b76c3e5aa4195a
# Parent  e10bc3910caa2cd61a93f68db29e44b5e18c73ea
fix read uninitialize memory warning in Valgrind-3.10.0
---
 source/encoder/entropy.cpp |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff -r e10bc3910caa -r 64aa89a464aa source/encoder/entropy.cpp
--- a/source/encoder/entropy.cpp	Tue Nov 24 10:18:25 2015 -0600
+++ b/source/encoder/entropy.cpp	Wed Nov 25 14:37:27 2015 -0600
@@ -1566,11 +1566,14 @@
     uint8_t * const baseCtx = bIsLuma ? &m_contextState[OFF_SIG_FLAG_CTX] : &m_contextState[OFF_SIG_FLAG_CTX + NUM_SIG_FLAG_CTX_LUMA];
     uint32_t c1 = 1;
     int scanPosSigOff = scanPosLast - (lastScanSet << MLS_CG_SIZE) - 1;
-    ALIGN_VAR_32(uint16_t, absCoeff[(1 << MLS_CG_SIZE) + 1]);   // extra 2 bytes space for AVX2 assembly
+    ALIGN_VAR_32(uint16_t, absCoeff[(1 << MLS_CG_SIZE) + 1]);   // extra 2 bytes(+1) space for AVX2 assembly, +1 because (numNonZero<=1) in costCoeffNxN path
     uint32_t numNonZero = 1;
     unsigned long lastNZPosInCG;
     unsigned long firstNZPosInCG;
 
+    // Unnecessary, for Valgrind-3.10.0 only
+    memset(absCoeff, 0, sizeof(absCoeff));
+
     absCoeff[0] = (uint16_t)abs(coeff[posLast]);
 
     for (int subSet = lastScanSet; subSet >= 0; subSet--)
@@ -1716,6 +1719,7 @@
             {
                 // maximum g_entropyBits are 18-bits and maximum of count are 16, so intermedia of sum are 22-bits
                 const uint8_t *tabSigCtx = table_cnt[(log2TrSize == 2) ? 4 : (uint32_t)patternSigCtx];
+                X265_CHECK(numNonZero <= 1, "numNonZero check failure");
                 uint32_t sum = primitives.costCoeffNxN(g_scan4x4[codingParameters.scanType], &coeff[blkPosBase], (intptr_t)trSize, absCoeff + numNonZero, tabSigCtx, scanFlagMask, baseCtx, offset + posOffset, scanPosSigOff, subPosBase);
 
 #if CHECKED_BUILD || _DEBUG



More information about the x265-devel mailing list