This is an automated email from the ASF dual-hosted git repository.

SpriCoder pushed a commit to branch cPerformance
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 8566fd9182c5100e5ed39e18d8496841c566cf15
Author: spricoder <[email protected]>
AuthorDate: Sun May 31 11:43:18 2026 +0800

    Use snprintf for Tablet bounds-check error messages
    
    Tablet::addValue and the OBJECT-value overload formatted out-of-range
    diagnostics with sprintf into a fixed 100-byte stack buffer, risking an
    overflow. Switch to snprintf bounded by sizeof(buffer) and cast the size_t
    arguments to long to match the %ld format.
---
 iotdb-client/client-cpp/src/main/Session.h | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/iotdb-client/client-cpp/src/main/Session.h 
b/iotdb-client/client-cpp/src/main/Session.h
index 4a629565af0..3f32b6c67d6 100644
--- a/iotdb-client/client-cpp/src/main/Session.h
+++ b/iotdb-client/client-cpp/src/main/Session.h
@@ -31,6 +31,7 @@
 #include <thread>
 #include <stdexcept>
 #include <cstdlib>
+#include <cstdio>
 #include <future>
 #include <boost/date_time/gregorian/gregorian.hpp>
 #include <thrift/protocol/TBinaryProtocol.h>
@@ -258,16 +259,17 @@ public:
   template <typename T> void addValue(size_t schemaId, size_t rowIndex, const 
T& value) {
     if (schemaId >= schemas.size()) {
       char tmpStr[100];
-      sprintf(tmpStr,
-              "Tablet::addValue(), schemaId >= schemas.size(). schemaId=%ld, 
schemas.size()=%ld.",
-              schemaId, schemas.size());
+      snprintf(tmpStr, sizeof(tmpStr),
+               "Tablet::addValue(), schemaId >= schemas.size(). schemaId=%ld, 
schemas.size()=%ld.",
+               (long)schemaId, (long)schemas.size());
       throw std::out_of_range(tmpStr);
     }
 
     if (rowIndex >= rowSize) {
       char tmpStr[100];
-      sprintf(tmpStr, "Tablet::addValue(), rowIndex >= rowSize. rowIndex=%ld, 
rowSize.size()=%ld.",
-              rowIndex, rowSize);
+      snprintf(tmpStr, sizeof(tmpStr),
+               "Tablet::addValue(), rowIndex >= rowSize. rowIndex=%ld, 
rowSize.size()=%ld.",
+               (long)rowIndex, (long)rowSize);
       throw std::out_of_range(tmpStr);
     }
 
@@ -317,19 +319,19 @@ public:
     // Check schemaId bounds
     if (schemaId >= schemas.size()) {
       char tmpStr[100];
-      sprintf(tmpStr,
-              "Tablet::addBinaryValueWithMeta(), schemaId >= schemas.size(). 
schemaId=%ld, "
-              "schemas.size()=%ld.",
-              schemaId, schemas.size());
+      snprintf(tmpStr, sizeof(tmpStr),
+               "Tablet::addBinaryValueWithMeta(), schemaId >= schemas.size(). 
schemaId=%ld, "
+               "schemas.size()=%ld.",
+               (long)schemaId, (long)schemas.size());
       throw std::out_of_range(tmpStr);
     }
 
     // Check rowIndex bounds
     if (rowIndex >= rowSize) {
       char tmpStr[100];
-      sprintf(tmpStr,
-              "Tablet::addBinaryValueWithMeta(), rowIndex >= rowSize. 
rowIndex=%ld, rowSize=%ld.",
-              rowIndex, rowSize);
+      snprintf(tmpStr, sizeof(tmpStr),
+               "Tablet::addBinaryValueWithMeta(), rowIndex >= rowSize. 
rowIndex=%ld, rowSize=%ld.",
+               (long)rowIndex, (long)rowSize);
       throw std::out_of_range(tmpStr);
     }
 

Reply via email to