shithub: openh264

Download patch

ref: c4e1d2bbb8fdb0078ce85bd5982bbb97515b394d
parent: 564d16c2efbb70c296a815ebd35ae69033475915
author: Martin Storsjö <martin@martin.st>
date: Mon Apr 21 18:03:47 EDT 2014

Simplify the use of return values from Wels*Snprintf

Also similarly simplify the use of the return value from
WelsStrftime and GetCodeName/GetLibName/GetVerNum.

--- a/codec/decoder/plus/src/welsDecoderExt.cpp
+++ b/codec/decoder/plus/src/welsDecoderExt.cpp
@@ -110,10 +110,8 @@
   iCurUsed     = WelsSnprintf (chFileName,  iBufLeft,  "bs_0x%p_", (void*)this);
   iCurUsedSize = WelsSnprintf (chFileNameSize, iBufLeftSize, "size_0x%p_", (void*)this);
 
-  if (iCurUsed > 0) {
-    iBufUsed += iCurUsed;
-    iBufLeft -= iCurUsed;
-  }
+  iBufUsed += iCurUsed;
+  iBufLeft -= iCurUsed;
   if (iBufLeft > 0) {
     iCurUsed = WelsStrftime (&chFileName[iBufUsed], iBufLeft, "%y%m%d%H%M%S", &sCurTime);
     iBufUsed += iCurUsed;
@@ -120,10 +118,8 @@
     iBufLeft -= iCurUsed;
   }
 
-  if (iCurUsedSize > 0) {
-    iBufUsedSize += iCurUsedSize;
-    iBufLeftSize -= iCurUsedSize;
-  }
+  iBufUsedSize += iCurUsedSize;
+  iBufLeftSize -= iCurUsedSize;
   if (iBufLeftSize > 0) {
     iCurUsedSize = WelsStrftime (&chFileNameSize[iBufUsedSize], iBufLeftSize, "%y%m%d%H%M%S", &sCurTime);
     iBufUsedSize += iCurUsedSize;
@@ -132,19 +128,15 @@
 
   if (iBufLeft > 0) {
     iCurUsed = WelsSnprintf (&chFileName[iBufUsed], iBufLeft, ".%03.3u.264", WelsGetMillisecond (&sCurTime));
-    if (iCurUsed > 0) {
-      iBufUsed += iCurUsed;
-      iBufLeft -= iCurUsed;
-    }
+    iBufUsed += iCurUsed;
+    iBufLeft -= iCurUsed;
   }
 
   if (iBufLeftSize > 0) {
     iCurUsedSize = WelsSnprintf (&chFileNameSize[iBufUsedSize], iBufLeftSize, ".%03.3u.len",
                                  WelsGetMillisecond (&sCurTime));
-    if (iCurUsedSize > 0) {
-      iBufUsedSize += iCurUsedSize;
-      iBufLeftSize -= iCurUsedSize;
-    }
+    iBufUsedSize += iCurUsedSize;
+    iBufLeftSize -= iCurUsedSize;
   }
 
 
--- a/codec/encoder/core/src/utils.cpp
+++ b/codec/encoder/core/src/utils.cpp
@@ -144,26 +144,20 @@
 
       WelsGetTimeOfDay(&tTime);
       iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, "[0x%p @ ", pEncCtx);	// confirmed_safe_unsafe_usage
-      if (iCurUsed >= 0) {
-        iBufUsed += iCurUsed;
-        iBufLeft -= iCurUsed;
-      }
+      iBufUsed += iCurUsed;
+      iBufLeft -= iCurUsed;
 
       if (iBufLeft > 0) {
         iCurUsed = GetCodeName (&pBuf[iBufUsed], iBufLeft);
-        if (iCurUsed > 0) {
-          iBufUsed += iCurUsed;
-          iBufLeft -= iCurUsed;
-        }
+        iBufUsed += iCurUsed;
+        iBufLeft -= iCurUsed;
         pBuf[iBufUsed] = ' ';
         ++ iBufUsed;
         -- iBufLeft;
 
         iCurUsed = GetLibName (&pBuf[iBufUsed], iBufLeft);
-        if (iCurUsed > 0) {
-          iBufUsed += iCurUsed;
-          iBufLeft -= iCurUsed;
-        }
+        iBufUsed += iCurUsed;
+        iBufLeft -= iCurUsed;
         pBuf[iBufUsed] = ' ';
         ++ iBufUsed;
         -- iBufLeft;
@@ -172,10 +166,8 @@
         ++ iBufUsed;
         -- iBufLeft;
         iCurUsed = GetVerNum (&pBuf[iBufUsed], iBufLeft);
-        if (iCurUsed > 0) {
-          iBufUsed += iCurUsed;
-          iBufLeft -= iCurUsed;
-        }
+        iBufUsed += iCurUsed;
+        iBufLeft -= iCurUsed;
         pBuf[iBufUsed] = ' ';
         ++ iBufUsed;
         -- iBufLeft;
@@ -183,10 +175,8 @@
 
       if (iBufLeft > 0) {
         iCurUsed = WelsStrftime (&pBuf[iBufUsed], iBufLeft, "%y-%m-%d %H:%M:%S", &tTime);
-        if (iCurUsed > 0) {
-          iBufUsed += iCurUsed;
-          iBufLeft -= iCurUsed;
-        }
+        iBufUsed += iCurUsed;
+        iBufLeft -= iCurUsed;
       } else {
         return;
       }
@@ -193,10 +183,8 @@
 
       if (iBufLeft > 0) {
         iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, ".%3.3u]: ", tTime.millitm);	// confirmed_safe_unsafe_usage
-        if (iCurUsed >= 0) {
-          iBufUsed += iCurUsed;
-          iBufLeft -= iCurUsed;
-        }
+        iBufUsed += iCurUsed;
+        iBufLeft -= iCurUsed;
       } else {
         return;
       }
@@ -209,18 +197,14 @@
       pStr	= GetLogTag (kiLevel, &i_shift);
       if (NULL != pStr) {
         iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, "%s ", pStr);
-        if (iCurUsed >= 0) {
-          iBufUsed += iCurUsed;
-          iBufLeft -= iCurUsed;
-        }
+        iBufUsed += iCurUsed;
+        iBufLeft -= iCurUsed;
       }
     }
     if (iBufLeft > 0) {
       iCurUsed = WelsVsnprintf (&pBuf[iBufUsed], iBufLeft, kpFmtStr, argv);	// confirmed_safe_unsafe_usage
-      if (iCurUsed > 0) {
-        iBufUsed += iCurUsed;
-        iBufLeft -= iCurUsed;
-      }
+      iBufUsed += iCurUsed;
+      iBufLeft -= iCurUsed;
     }
 #ifdef ENABLE_TRACE_FILE
     if (NULL != pEncCtx && NULL != pEncCtx->pFileLog) {
--- a/codec/encoder/plus/src/welsEncoderExt.cpp
+++ b/codec/encoder/plus/src/welsEncoderExt.cpp
@@ -90,10 +90,8 @@
   iCurUsedSize  = WelsSnprintf (strLenFileName, iBufferLeftSize, "enc_size_0x%p_", (void*)this);
 
 
-  if (iCurUsed > 0) {
-    iBufferUsed += iCurUsed;
-    iBufferLeft -= iCurUsed;
-  }
+  iBufferUsed += iCurUsed;
+  iBufferLeft -= iCurUsed;
   if (iBufferLeft > 0) {
     iCurUsed = WelsStrftime (&strStreamFileName[iBufferUsed], iBufferLeft, "%y%m%d%H%M%S", &tTime);
     iBufferUsed += iCurUsed;
@@ -100,10 +98,8 @@
     iBufferLeft -= iCurUsed;
   }
 
-  if (iCurUsedSize > 0) {
-    iBufferUsedSize += iCurUsedSize;
-    iBufferLeftSize -= iCurUsedSize;
-  }
+  iBufferUsedSize += iCurUsedSize;
+  iBufferLeftSize -= iCurUsedSize;
   if (iBufferLeftSize > 0) {
     iCurUsedSize = WelsStrftime (&strLenFileName[iBufferUsedSize], iBufferLeftSize, "%y%m%d%H%M%S", &tTime);
     iBufferUsedSize += iCurUsedSize;
@@ -113,19 +109,15 @@
   if (iBufferLeft > 0) {
     iCurUsed = WelsSnprintf (&strStreamFileName[iBufferUsed], iBufferLeft, ".%03.3u.264",
                              WelsGetMillisecond(&tTime));
-    if (iCurUsed > 0) {
-      iBufferUsed += iCurUsed;
-      iBufferLeft -= iCurUsed;
-    }
+    iBufferUsed += iCurUsed;
+    iBufferLeft -= iCurUsed;
   }
 
   if (iBufferLeftSize > 0) {
     iCurUsedSize = WelsSnprintf (&strLenFileName[iBufferUsedSize], iBufferLeftSize, ".%03.3u.len",
                                  WelsGetMillisecond(&tTime));
-    if (iCurUsedSize > 0) {
-      iBufferUsedSize += iCurUsedSize;
-      iBufferLeftSize -= iCurUsedSize;
-    }
+    iBufferUsedSize += iCurUsedSize;
+    iBufferLeftSize -= iCurUsedSize;
   }
 
   m_pFileBs     = WelsFopen (strStreamFileName, "wb");