shithub: openh264

Download patch

ref: a344d100ae37ac69b0e1a6ac0b9d7d5f1328b86a
parent: 98bad4f2b3f3199e0e8dadfafc85b00b8561bb6a
author: Martin Storsjö <martin@martin.st>
date: Sat Jan 25 19:40:22 EST 2014

Fix buffer size checks when appending using SNPRINTF/WelsSnprintf

Checking iBufferLeft > iBufferUsed does not make sense, since
this would stop writing into the buffer alredy after the buffer
is half full, when there is less space left than has been used.

The right check is iBufferLeft > 0.

--- a/codec/decoder/plus/src/welsDecoderExt.cpp
+++ b/codec/decoder/plus/src/welsDecoderExt.cpp
@@ -110,23 +110,23 @@
   iBufUsedSize += WelsSnprintf (chFileNameSize, iBufLeftSize, "size_0x%p_", (void_t*)this);
 
   iBufLeft -= iBufUsed;
-  if (iBufLeft > iBufUsed) {
+  if (iBufLeft > 0) {
     iBufUsed += WelsStrftime (&chFileName[iBufUsed], iBufLeft, "%y%m%d%H%M%S", &sCurTime);
     iBufLeft -= iBufUsed;
   }
 
   iBufLeftSize -= iBufUsedSize;
-  if (iBufLeftSize > iBufUsedSize) {
+  if (iBufLeftSize > 0) {
     iBufUsedSize += WelsStrftime (&chFileNameSize[iBufUsedSize], iBufLeftSize, "%y%m%d%H%M%S", &sCurTime);
     iBufLeftSize -= iBufUsedSize;
   }
 
-  if (iBufLeft > iBufUsed) {
+  if (iBufLeft > 0) {
     iBufUsed += WelsSnprintf (&chFileName[iBufUsed], iBufLeft, ".%03.3u.264", WelsGetMillsecond (&sCurTime));
     iBufLeft -= iBufUsed;
   }
 
-  if (iBufLeftSize > iBufUsedSize) {
+  if (iBufLeftSize > 0) {
     iBufUsedSize += WelsSnprintf (&chFileNameSize[iBufUsedSize], iBufLeftSize, ".%03.3u.len",
                                   WelsGetMillsecond (&sCurTime));
     iBufLeftSize -= iBufUsedSize;
--- a/codec/encoder/plus/src/welsEncoderExt.cpp
+++ b/codec/encoder/plus/src/welsEncoderExt.cpp
@@ -132,7 +132,7 @@
 
 
   iBufferLeft -= iBufferUsed;
-  if (iBufferLeft > iBufferUsed) {
+  if (iBufferLeft > 0) {
 #if defined(_GNUC__)
     iBufferUsed += strftime (&strStreamFileName[iBufferUsed], iBufferLeft, "%y%m%d%H%M%S", tTimeNow);
 #else
@@ -150,7 +150,7 @@
   }
 
   iBufferLeftSize -= iBufferUsedSize;
-  if (iBufferLeftSize > iBufferUsedSize) {
+  if (iBufferLeftSize > 0) {
 #if defined(_GNUC__)
     iBufferUsedSize += strftime (&strLenFileName[iBufferUsedSize], iBufferLeftSize, "%y%m%d%H%M%S", tTimeNow);
 #else
@@ -167,7 +167,7 @@
     iBufferLeftSize -= iBufferUsedSize;
   }
 
-  if (iBufferLeft > iBufferUsed) {
+  if (iBufferLeft > 0) {
 #ifdef _WIN32
 #if defined(_MSC_VER)
 #if _MSC_VER>=1500
@@ -182,7 +182,7 @@
     iBufferLeft -= iBufferUsed;
   }
 
-  if (iBufferLeftSize > iBufferUsedSize) {
+  if (iBufferLeftSize > 0) {
 #ifdef _WIN32
 #if defined(_MSC_VER)
 #if _MSC_VER>=1500