shithub: openh264

Download patch

ref: 493c31f6a6bf433637a0e24a888c7812b1676d7e
parent: 9b0de456c3d75e10bdcd95d03661950ea270457b
parent: 1d86dbdc0f903f07364b6f48b56f8f60017b2281
author: Licai Guo <licaguo@cisco.com>
date: Wed Jan 22 18:50:47 EST 2014

Merge pull request #174 from volvet/coverity_issue_fix

fix coverity issues 26973, 26974, 26975, 26976, 26972, 26980.

--- a/codec/encoder/core/src/ref_list_mgr_svc.cpp
+++ b/codec/encoder/core/src/ref_list_mgr_svc.cpp
@@ -224,7 +224,7 @@
         }
 
         pLtr->iLTRMarkSuccessNum++;
-        pLtr->iCurLtrIdx = (++pLtr->iCurLtrIdx % LONG_TERM_REF_NUM);
+        pLtr->iCurLtrIdx = (pLtr->iCurLtrIdx+1)%LONG_TERM_REF_NUM;
         pLtr->iLTRMarkMode = (pLtr->iLTRMarkSuccessNum >= (LONG_TERM_REF_NUM)) ? (LTR_DELAY_MARK) : (LTR_DIRECT_MARK);
         WelsLog (pCtx, WELS_LOG_WARNING, "LTR mark mode =%d", pLtr->iLTRMarkMode);
         pLtr->bLTRMarkEnable = TRUE;
@@ -350,27 +350,27 @@
   if (NULL == pRefList || NULL == pRefList->pRef[0] || NULL == pRefList->pRef[kiSwapIdx])
     return FALSE;
 
-  if ((NULL != pCtx->pDecPic)
+  if (NULL != pCtx->pDecPic) {
 #if !defined(ENABLE_FRAME_DUMP)	// to save complexity, 1/6/2009
-      && (pParamD->iHighestTemporalId == 0 || kuiTid < pParamD->iHighestTemporalId)
+    if ((pParamD->iHighestTemporalId == 0) || (kuiTid < pParamD->iHighestTemporalId))
 #endif// !ENABLE_FRAME_DUMP
-     )
     // Expanding picture for future reference
     ExpandReferencingPicture (pCtx->pDecPic, pCtx->pFuncList->pfExpandLumaPicture, pCtx->pFuncList->pfExpandChromaPicture);
 
-  // move picture in list
-  pCtx->pDecPic->uiTemporalId = kuiTid;
-  pCtx->pDecPic->uiSpatialId	= kuiDid;
-  pCtx->pDecPic->iFrameNum		= pCtx->iFrameNum;
-  pCtx->pDecPic->iFramePoc		= pCtx->iPOC;
-  pCtx->pDecPic->uiRecieveConfirmed = RECIEVE_UNKOWN;
-  pCtx->pDecPic->bUsedAsRef	= true;
+    // move picture in list
+    pCtx->pDecPic->uiTemporalId = kuiTid;
+    pCtx->pDecPic->uiSpatialId	= kuiDid;
+    pCtx->pDecPic->iFrameNum	= pCtx->iFrameNum;
+    pCtx->pDecPic->iFramePoc	= pCtx->iPOC;
+    pCtx->pDecPic->uiRecieveConfirmed = RECIEVE_UNKOWN;
+    pCtx->pDecPic->bUsedAsRef	= true;
 
-  for (iRefIdx = pRefList->uiShortRefCount - 1; iRefIdx >= 0; --iRefIdx)	{
-    pRefList->pShortRefList[iRefIdx + 1] = pRefList->pShortRefList[iRefIdx];
+    for (iRefIdx = pRefList->uiShortRefCount - 1; iRefIdx >= 0; --iRefIdx)	{
+      pRefList->pShortRefList[iRefIdx + 1] = pRefList->pShortRefList[iRefIdx];
+    }
+    pRefList->pShortRefList[0] = pCtx->pDecPic;
+    pRefList->uiShortRefCount++;
   }
-  pRefList->pShortRefList[0] = pCtx->pDecPic;
-  pRefList->uiShortRefCount++;
 
   if (keSliceType == P_SLICE) {
     if (pCtx->uiTemporalId == 0) {
@@ -398,7 +398,7 @@
     if (pCtx->pSvcParam->bEnableLongTermReference)	{
       LTRMarkProcess (pCtx);
 
-      pLtr->iCurLtrIdx = (++pLtr->iCurLtrIdx % LONG_TERM_REF_NUM);
+      pLtr->iCurLtrIdx = (pLtr->iCurLtrIdx+1)%LONG_TERM_REF_NUM;
       pLtr->iLTRMarkSuccessNum = 1; //IDR default suceess
       pLtr->bLTRMarkEnable =  TRUE;
       pLtr->uiLtrMarkInterval = 0;
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -649,21 +649,19 @@
     (*ppCtx)->pSliceBs = NULL;
   }
 #if defined(DYNAMIC_SLICE_ASSIGN) || defined(MT_DEBUG)
-  if (pSmt->pSliceConsumeTime != NULL) {
-    iIdx = 0;
-    while (iIdx < pCodingParam->iNumDependencyLayer) {
-      if (pSmt->pSliceConsumeTime[iIdx]) {
-        pMa->WelsFree (pSmt->pSliceConsumeTime[iIdx], "pSliceConsumeTime[]");
-        pSmt->pSliceConsumeTime[iIdx] = NULL;
-      }
+  iIdx = 0;
+  while (iIdx < pCodingParam->iNumDependencyLayer) {
+    if (pSmt->pSliceConsumeTime[iIdx]) {
+      pMa->WelsFree (pSmt->pSliceConsumeTime[iIdx], "pSliceConsumeTime[]");
+      pSmt->pSliceConsumeTime[iIdx] = NULL;
+    }
 #if defined(DYNAMIC_SLICE_ASSIGN) && defined(TRY_SLICING_BALANCE)
-      if (pSmt->pSliceComplexRatio[iIdx] != NULL) {
-        pMa->WelsFree (pSmt->pSliceComplexRatio[iIdx], "pSliceComplexRatio[]");
-        pSmt->pSliceComplexRatio[iIdx] = NULL;
-      }
-#endif//TRY_SLICING_BALANCE
-      ++ iIdx;
+    if (pSmt->pSliceComplexRatio[iIdx] != NULL) {
+      pMa->WelsFree (pSmt->pSliceComplexRatio[iIdx], "pSliceComplexRatio[]");
+      pSmt->pSliceComplexRatio[iIdx] = NULL;
     }
+#endif//TRY_SLICING_BALANCE
+    ++ iIdx;
   }
 #endif//#if defined(DYNAMIC_SLICE_ASSIGN) || defined(MT_DEBUG)
 
--- a/codec/encoder/core/src/utils.cpp
+++ b/codec/encoder/core/src/utils.cpp
@@ -179,20 +179,16 @@
       t_now = (struct tm*)LOCALTIME (&l_time);
       gettimeofday (&tv, NULL);
 #endif//WIN32
-      if (iBufLeft > 0) {
 #ifdef _MSC_VER
 #if _MSC_VER >= 1500
-        iCurUsed = SNPRINTF (&pBuf[iBufUsed], iBufLeft, iBufLeft, "[0x%p @ ", pEncCtx);	// confirmed_safe_unsafe_usage
+      iCurUsed = SNPRINTF (&pBuf[iBufUsed], iBufLeft, iBufLeft, "[0x%p @ ", pEncCtx);	// confirmed_safe_unsafe_usage
 #else
-        iCurUsed = SNPRINTF (&pBuf[iBufUsed], iBufLeft, "[0x%p @ ", pEncCtx);	// confirmed_safe_unsafe_usage
+      iCurUsed = SNPRINTF (&pBuf[iBufUsed], iBufLeft, "[0x%p @ ", pEncCtx);	// confirmed_safe_unsafe_usage
 #endif//_MSC_VER >= 1500
 #endif//_MSC_VER
-        if (iCurUsed >= 0) {
-          iBufUsed += iCurUsed;
-          iBufLeft -= iCurUsed;
-        }
-      } else {
-        return;
+      if (iCurUsed >= 0) {
+        iBufUsed += iCurUsed;
+        iBufLeft -= iCurUsed;
       }
 
       if (iBufLeft > 0) {
--- a/codec/encoder/core/src/wels_preprocess.cpp
+++ b/codec/encoder/core/src/wels_preprocess.cpp
@@ -452,8 +452,6 @@
       // spatial layer is able to encode indeed
       if ((iTemporalId != INVALID_TEMPORAL_ID)) {
         // down sampling performed
-        if (NULL == pSrcPic)
-          return -1;
 
         pDstPic	= pEncCtx->pSpatialPic[iDependencyId][iPicturePos];	// small
         iShrinkWidth = pScaledPicture->iScaledWidth[iDependencyId];