shithub: openh264

Download patch

ref: 0fc550221585d252f2beb3b6720469875673910b
parent: cbc0adb52f8ab053a961255ab115c59b1aabb724
author: xiaotiansf <[email protected]>
date: Mon Feb 18 09:07:04 EST 2019

Fix ossz-buzz reported bug 13185: make the code to be more readable.

--- a/codec/decoder/core/src/decoder.cpp
+++ b/codec/decoder/core/src/decoder.cpp
@@ -165,6 +165,24 @@
   return ERR_NONE;
 }
 
+static void ResetRefPicReferences (const PWelsDecoderContext& pCtx, const PPicture& inPPic) {
+  //seach and reset the references of deleted references.
+  for (int32_t list = LIST_0; list < LIST_A; ++list) {
+    int32_t refIdx = 0;
+    PPicture pPic = pCtx->sRefPic.pRefList[list][refIdx];
+    while (refIdx < MAX_DPB_COUNT && pPic != NULL) {
+      ++refIdx;
+      int32_t ref = 0;
+      while (ref < MAX_DPB_COUNT && *pPic->pRefPic[ref] != NULL) {
+        if (*pPic->pRefPic[ref] == inPPic) {
+          *pPic->pRefPic[ref] = NULL;
+        }
+        ++ref;
+      }
+    }
+  }
+}
+
 static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, const int32_t kiOldSize,
                                 const int32_t kiPicWidth, const int32_t kiPicHeight, const int32_t kiNewSize) {
   PPicBuff pPicOldBuf = *ppPicBuf;
@@ -212,22 +230,8 @@
   for (iPicIdx = iDelIdx; iPicIdx < kiOldSize; iPicIdx++) {
     if (iPrevPicIdx != iPicIdx) {
       if (pPicOldBuf->ppPic[iPicIdx] != NULL) {
+        ResetRefPicReferences (pCtx, pPicOldBuf->ppPic[iPicIdx]);
         FreePicture (pPicOldBuf->ppPic[iPicIdx], pMa);
-        //seach and reset the references of deleted references.
-        for (int32_t list = LIST_0; list < LIST_A; ++list) {
-          int32_t refIdx = 0;
-          PPicture pPic = pCtx->sRefPic.pRefList[list][refIdx];
-          while (refIdx < MAX_DPB_COUNT && pPic != NULL) {
-            ++refIdx;
-            int32_t ref = 0;
-            while (ref < MAX_DPB_COUNT && *pPic->pRefPic[ref] != NULL) {
-              if (*pPic->pRefPic[ref] == pPicOldBuf->ppPic[iPicIdx]) {
-                *pPic->pRefPic[ref] = NULL;
-              }
-              ++ref;
-            }
-          }
-        }
         pPicOldBuf->ppPic[iPicIdx] = NULL;
       }
     }