shithub: openh264

Download patch

ref: 7791a6d28d10223f441d0016819752a218b1a10b
parent: 031892265497de13b3f0c0305a00b0dbe2ddba24
author: Martin Storsjö <martin@martin.st>
date: Tue Jan 28 06:50:17 EST 2014

Use WelsSnprintf instead of a combination of strlen and STRNCAT

This simplifies the code and makes the buffer size checks
more consistent. Additionally, the previous version wrote
the extra space character without checking if it actually fit
into the buffer.

--- a/codec/encoder/core/src/utils.cpp
+++ b/codec/encoder/core/src/utils.cpp
@@ -208,13 +208,11 @@
       str_t* pStr = NULL;
       pStr	= GetLogTag (kiLevel, &i_shift);
       if (NULL != pStr) {
-        int32_t iLenTag = strlen (pStr);	// confirmed_safe_unsafe_usage
-        STRCAT (&pBuf[iBufUsed], iBufLeft, pStr);	// confirmed_safe_unsafe_usage
-        iBufUsed += iLenTag;
-        pBuf[iBufUsed] = ' ';
-        iBufUsed++;
-        ++iLenTag;
-        iBufLeft -= iLenTag;
+        iCurUsed = WelsSnprintf (&pBuf[iBufUsed], iBufLeft, "%s ", pStr);
+        if (iCurUsed >= 0) {
+          iBufUsed += iCurUsed;
+          iBufLeft -= iCurUsed;
+        }
       }
     }
     if (iBufLeft > 0) {