[x265] [PATCH] Fix the buffer size issue

Ponsanthini Arunachalam ponsanthini.arunachalam at multicorewareinc.com
Thu Oct 17 16:06:07 UTC 2024


>From dd1dc1f882b6f45422741e8b64da92c272e70e75 Mon Sep 17 00:00:00 2001
From: Ponsanthini <ponsanthini.arunachalam at multicorewareinc.com>
Date: Wed, 16 Oct 2024 19:37:39 +0530
Subject: [PATCH] Fix the buffer size issue

---
 source/encoder/encoder.cpp | 17 +++++++++--------
 source/encoder/encoder.h   |  2 +-
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp
index 21a4d5518..607c80d86 100644
--- a/source/encoder/encoder.cpp
+++ b/source/encoder/encoder.cpp
@@ -2789,15 +2789,16 @@ void EncStats::addQP(double aveQp)
     m_totalQp += aveQp;
 }

-char* Encoder::statsString(EncStats& stat, char* buffer)
+char* Encoder::statsString(EncStats& stat, char* buffer, size_t bufferSize)
 {
     double fps = (double)m_param->fpsNum / m_param->fpsDenom;
     double scale = fps / 1000 / (double)stat.m_numPics;

-    int len = snprintf(buffer, sizeof(buffer), "%6u, ", stat.m_numPics);
-
-    len += snprintf(buffer + len, sizeof(buffer) - len, "Avg QP:%2.2lf",
stat.m_totalQp / (double)stat.m_numPics);
-    len += snprintf(buffer + len, sizeof(buffer) - len, "  kb/s: %-8.2lf",
stat.m_accBits * scale);
+    int len = snprintf(buffer, bufferSize, "%6u, ", stat.m_numPics);
+
+    len += snprintf(buffer + len, bufferSize - len, "Avg QP:%2.2lf",
stat.m_totalQp / (double)stat.m_numPics);
+    len += snprintf(buffer + len, bufferSize - len, "  kb/s: %-8.2lf",
stat.m_accBits * scale);
+
     if (m_param->bEnablePsnr)
     {
         len += snprintf(buffer + len, sizeof(buffer) - len,"  PSNR Mean:
Y:%.3lf U:%.3lf V:%.3lf",
@@ -2823,11 +2824,11 @@ void Encoder::printSummary()
     {
         char buffer[200];
         if (m_analyzeI[layer].m_numPics)
-            x265_log(m_param, X265_LOG_INFO, "frame I: %s\n",
statsString(m_analyzeI[layer], buffer));
+            x265_log(m_param, X265_LOG_INFO, "frame I: %s\n",
statsString(m_analyzeI[layer], buffer, sizeof(buffer)));
         if (m_analyzeP[layer].m_numPics)
-            x265_log(m_param, X265_LOG_INFO, "frame P: %s\n",
statsString(m_analyzeP[layer], buffer));
+            x265_log(m_param, X265_LOG_INFO, "frame P: %s\n",
statsString(m_analyzeP[layer], buffer, sizeof(buffer)));
         if (m_analyzeB[layer].m_numPics)
-            x265_log(m_param, X265_LOG_INFO, "frame B: %s\n",
statsString(m_analyzeB[layer], buffer));
+            x265_log(m_param, X265_LOG_INFO, "frame B: %s\n",
statsString(m_analyzeB[layer], buffer, sizeof(buffer)));
         if (m_param->bEnableWeightedPred && m_analyzeP[layer].m_numPics)
         {
             x265_log(m_param, X265_LOG_INFO, "Weighted P-Frames: Y:%.1f%%
UV:%.1f%%\n",
diff --git a/source/encoder/encoder.h b/source/encoder/encoder.h
index 4b72f8bf9..f50f783d0 100644
--- a/source/encoder/encoder.h
+++ b/source/encoder/encoder.h
@@ -328,7 +328,7 @@ public:

     void printReconfigureParams();

-    char* statsString(EncStats&, char*);
+    char* statsString(EncStats&, char* , size_t bufferSize);

     void configure(x265_param *param);

-- 
2.41.0.windows.3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241017/9fd441f1/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-buffer-size-issue.diff
Type: application/octet-stream
Size: 3051 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241017/9fd441f1/attachment.obj>


More information about the x265-devel mailing list