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

bbender pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git


The following commit(s) were added to refs/heads/develop by this push:
     new 10d2484  GEODE-9553: remove sprintf and snprintf from geode native 
(#871)
10d2484 is described below

commit 10d248406ffc3796a52bfdd641188f1aec696945
Author: Blake Bender <[email protected]>
AuthorDate: Thu Sep 30 10:50:42 2021 -0700

    GEODE-9553: remove sprintf and snprintf from geode native (#871)
    
    * GEODE-9553: Replace instances of sprintf and snprintf in geode native
    - Occasionally one of these will pop up as an error in a new compiler,
      and really they have no place in a modern C++ codebase.
    - Just the product code (mostly) for now, we'll do test code in another PR
---
 clicache/src/impl/ManagedString.hpp                |   6 -
 cppcache/integration-test/testThinClientCqIR.cpp   |  12 +-
 cppcache/integration/test/ThinClientConflation.cpp | 162 --------------------
 cppcache/src/CqEventImpl.cpp                       |  13 +-
 cppcache/src/PdxFieldType.cpp                      |  10 +-
 cppcache/src/PdxInstanceImpl.cpp                   |  14 +-
 cppcache/src/PutAllPartialResult.hpp               |  27 ++--
 cppcache/src/RegionFactory.cpp                     |   4 +-
 cppcache/src/RemoteQuery.cpp                       |   9 +-
 cppcache/src/TcrMessage.cpp                        |  56 +++----
 cppcache/src/ThinClientRegion.cpp                  |   5 +-
 cppcache/src/Utils.cpp                             |   5 +-
 cppcache/src/statistics/AtomicStatisticsImpl.cpp   |  57 +++----
 cppcache/src/statistics/OsStatisticsImpl.cpp       |  75 ++++------
 sqliteimpl/SqLiteHelper.cpp                        |  44 +++---
 sqliteimpl/SqLiteHelper.hpp                        |   7 -
 tests/cpp/testobject/Portfolio.cpp                 | 164 ++++++++++-----------
 tests/cpp/testobject/Portfolio.hpp                 |  92 ++++++------
 tests/cpp/testobject/PortfolioPdx.cpp              | 143 +++++++++---------
 tests/cpp/testobject/PortfolioPdx.hpp              |  75 +++++-----
 20 files changed, 348 insertions(+), 632 deletions(-)

diff --git a/clicache/src/impl/ManagedString.hpp 
b/clicache/src/impl/ManagedString.hpp
index 8945ba9..ec702de 100644
--- a/clicache/src/impl/ManagedString.hpp
+++ b/clicache/src/impl/ManagedString.hpp
@@ -22,12 +22,6 @@
 
 #include "../geode_defs.hpp"
 
-#ifdef _WIN32
-// FIXME: Why is this needed?
-//#define snprintf _snprintf
-#endif
-
-
 using namespace System;
 
 namespace Apache
diff --git a/cppcache/integration-test/testThinClientCqIR.cpp 
b/cppcache/integration-test/testThinClientCqIR.cpp
index 2bf4489..e108adf 100644
--- a/cppcache/integration-test/testThinClientCqIR.cpp
+++ b/cppcache/integration-test/testThinClientCqIR.cpp
@@ -194,7 +194,7 @@ DUNIT_TASK_DEFINITION(CLIENT1, QueryData)
         count--;
 
         if (ser) {
-          printf(" query pulled object %s\n", ser->toString().c_str());
+          printf(" query pulled object '%s'\n", ser->toString().c_str());
 
           auto stPtr = std::dynamic_pointer_cast<Struct>(ser);
           ASSERT(stPtr != nullptr, "Failed to get struct in CQ result.");
@@ -204,7 +204,7 @@ DUNIT_TASK_DEFINITION(CLIENT1, QueryData)
           ASSERT(serKey != nullptr, "Failed to get KEY in CQ result.");
           if (serKey != nullptr) {
             LOG("got struct key ");
-            printf("  got struct key %s\n", serKey->toString().c_str());
+            printf("  got struct key '%s'\n", serKey->toString().c_str());
           }
 
           auto serVal = (*stPtr)["value"];
@@ -212,7 +212,7 @@ DUNIT_TASK_DEFINITION(CLIENT1, QueryData)
 
           if (serVal != nullptr) {
             LOG("got struct value ");
-            printf("  got struct value %s\n", serVal->toString().c_str());
+            printf("  got struct value '%s'\n", serVal->toString().c_str());
           }
         } else {
           printf("   query pulled bad object\n");
@@ -235,7 +235,7 @@ DUNIT_TASK_DEFINITION(CLIENT1, QueryData)
         count--;
 
         if (ser) {
-          printf(" query pulled object %s\n", ser->toString().c_str());
+          printf(" query pulled object '%s'\n", ser->toString().c_str());
 
           auto stPtr = std::dynamic_pointer_cast<Struct>(ser);
           ASSERT(stPtr != nullptr, "Failed to get struct in CQ result.");
@@ -245,7 +245,7 @@ DUNIT_TASK_DEFINITION(CLIENT1, QueryData)
           ASSERT(serKey != nullptr, "Failed to get KEY in CQ result.");
           if (serKey != nullptr) {
             LOG("got struct key ");
-            printf("  got struct key %s\n", serKey->toString().c_str());
+            printf("  got struct key '%s'\n", serKey->toString().c_str());
           }
 
           auto serVal = (*stPtr)["value"];
@@ -253,7 +253,7 @@ DUNIT_TASK_DEFINITION(CLIENT1, QueryData)
 
           if (serVal != nullptr) {
             LOG("got struct value ");
-            printf("  got struct value %s\n", serVal->toString().c_str());
+            printf("  got struct value '%s'\n", serVal->toString().c_str());
           }
         } else {
           printf("   query pulled bad object\n");
diff --git a/cppcache/integration/test/ThinClientConflation.cpp 
b/cppcache/integration/test/ThinClientConflation.cpp
deleted file mode 100644
index 26b9347..0000000
--- a/cppcache/integration/test/ThinClientConflation.cpp
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <framework/Cluster.h>
-#include <framework/Framework.h>
-#include <framework/Gfsh.h>
-
-#include <gtest/gtest.h>
-
-class ThinClient : ::testing::Test {
-  class OperMonitor : public CacheListener {
-    int m_events;
-    int m_value;
-
-    void check(const EntryEvent &event) {
-      char buf[256] = {'\0'};
-      m_events++;
-      auto keyPtr = std::dynamic_pointer_cast<CacheableString>(event.getKey());
-      auto valuePtr =
-          std::dynamic_pointer_cast<CacheableInt32>(event.getNewValue());
-
-      if (valuePtr != nullptr) {
-        m_value = valuePtr->value();
-      }
-      sprintf(buf, "Key = %s, Value = %d", keyPtr->toString().c_str(),
-              valuePtr->value());
-      LOG(buf);
-    }
-
-   public:
-    OperMonitor() : m_events(0), m_value(0) {}
-    ~OperMonitor() {}
-
-    virtual void afterCreate(const EntryEvent &event) { check(event); }
-
-    virtual void afterUpdate(const EntryEvent &event) { check(event); }
-
-    void validate(bool conflation) {
-      LOG("validate called");
-      char buf[256] = {'\0'};
-
-      if (conflation) {
-        sprintf(buf, "Conflation On: Expected events = 2, Actual = %d",
-                m_events);
-        ASSERT(m_events == 2, buf);
-      } else {
-        sprintf(buf, "Conflation Off: Expected events = 5, Actual = %d",
-                m_events);
-        ASSERT(m_events == 5, buf);
-      }
-      sprintf(buf, "Expected Value = 5, Actual = %d", m_value);
-      ASSERT(m_value == 5, buf);
-    }
-  };
-
-  void configure_pool(apache::geode::client::Cache &cache) {
-    auto poolFactory = cache.getPoolManager()
-                           .createFactory()
-                           .setSubscriptionRedundancy(0)
-                           .setSubscriptionEnabled(true)
-                           
.setSubscriptionAckInterval(std::chrono::seconds(1));
-
-    cluster_.applyLocators(poolFactory);
-
-    poolFactory.create("__TESTPOOL1_");
-  }
-
-  void configure_regions(apache::geode::client::Cache &cache) {
-    auto conflated_regionFactory =
-        conflated_cache_.createRegionFactory(RegionShortcut::CACHING_PROXY)
-            .setPoolName("__TESTPOOL1_");
-
-    auto conflated = regionFactory.create("ConflatedRegion");
-    auto non_conflated = regionFactory.create("NonConflatedRegion");
-
-    conflated->getAttributesMutator()->setCacheListener(
-        std::make_shared<OperMonitor>());
-    non - conflated->getAttributesMutator()->setCacheListener(
-              std::make_shared<OperMonitor>());
-  }
-
-  void configure_cache(apache::geode::client::Cache &cache) {
-    configure_pool(cache);
-    configure_regions(cache);
-  }
-
- protected:
-  Cluster cluster_{LocatorCount{1}, ServerCount{1}};
-  apache::geode::client::Cache conflated_cache_{
-      apache::geode::client::CacheFactory()
-          .set("log-level", "none")
-          .set("statistic-sampling-enabled", "false")
-          .set("durable-client-id", "DurableId1")
-          .set("durable-timeout", std::chrono::seconds(300))
-          .set("conflate-events", "true")
-          .create()},
-      non_conflated_cache_{
-          apache::geode::client::CacheFactory()
-              .set("log-level", "none")
-              .set("statistic-sampling-enabled", "false")
-              .set("durable-client-id", "DurableId2")
-              .set("durable-timeout", std::chrono::seconds(300))
-              .set("conflate-events", "false")
-              .create()},
-      feeder_cache_{apache::geode::client::CacheFactory()
-                        .set("log-level", "none")
-                        .set("statistic-sampling-enabled", "false")
-                        .set("durable-client-id", "DurableId1")
-                        .set("durable-timeout", std::chrono::seconds(300))
-                        .set("conflate-events", "true")
-                        .create()};
-
-  ThinClient() {
-    cluster_.start();
-
-    cluster_.getGfsh()
-        .create()
-        .region()
-        .withName("ConflatedRegion")
-        .withType("REPLICATE")
-        .execute();
-
-    cluster_.getGfsh()
-        .create()
-        .region()
-        .withName("NonConflatedRegion")
-        .withType("REPLICATE")
-        .execute();
-
-    configure_cache(conflated_cache_);
-    configure_cache(non_conflated_cache_);
-    configure_cache(feeder_cache_);
-  }
-};
-
-TEST_F(ThinClient, Conflation) {
-  auto conflated = feeder_cache_.getRegion("ConflatedRegion");
-
-  for(auto i = 1; i < 6; ++i) {
-    conflated.put(std::string("Key-").append(std::to_string(i)), i);
-  }
-
-  auto non_conflated = feeder_cache_.getRegion("NonConflatedRegion");
-
-  for(auto i = 1; i < 6; ++i) {
-    non_conflated.put(std::string("Key-").append(std::to_string(i)), i);
-  }
-}
\ No newline at end of file
diff --git a/cppcache/src/CqEventImpl.cpp b/cppcache/src/CqEventImpl.cpp
index a824fa6..a7c1f23 100644
--- a/cppcache/src/CqEventImpl.cpp
+++ b/cppcache/src/CqEventImpl.cpp
@@ -94,15 +94,12 @@ std::shared_ptr<Cacheable> CqEventImpl::getNewValue() const 
{
 bool CqEventImpl::getError() { return m_error; }
 
 std::string CqEventImpl::toString() {
-  char buffer[1024];
-  std::snprintf(
-      buffer, 1024,
-      "CqEvent CqName=%s; base operation=%d; cq operation= %d;key=%s;value=%s",
-      m_cQuery->getName().c_str(), static_cast<int>(m_baseOp),
-      static_cast<int>(m_queryOp), m_key->toString().c_str(),
-      m_newValue->toString().c_str());
-  return buffer;
+  return std::string("CqEvent CqName=") + m_cQuery->getName() +
+         "; base operation=" + std::to_string(static_cast<int>(m_baseOp)) +
+         "; cq operation=" + std::to_string(static_cast<int>(m_queryOp)) +
+         "; key=" + m_key->toString() + "; value=" + m_newValue->toString();
 }
+
 std::shared_ptr<CacheableBytes> CqEventImpl::getDeltaValue() const {
   return m_deltaValue;
 }
diff --git a/cppcache/src/PdxFieldType.cpp b/cppcache/src/PdxFieldType.cpp
index 596ef00..1f8026c 100644
--- a/cppcache/src/PdxFieldType.cpp
+++ b/cppcache/src/PdxFieldType.cpp
@@ -140,12 +140,10 @@ int32_t PdxFieldType::getFixedTypeSize() const {
 }
 
 std::string PdxFieldType::toString() const {
-  char stringBuf[1024];
-  std::snprintf(stringBuf, 1024,
-                " PdxFieldName=%s TypeId=%d VarLenFieldIdx=%d sequenceid=%d\n",
-                this->m_fieldName.c_str(), static_cast<int>(this->m_typeId),
-                this->m_varLenFieldIdx, this->m_sequenceId);
-  return std::string(stringBuf);
+  return std::string("PdxFieldName=") + m_fieldName +
+         " TypeId=" + std::to_string(static_cast<int>(m_typeId)) +
+         " VarLenFieldIdx=" + std::to_string(m_varLenFieldIdx) +
+         " sequenceid=" + std::to_string(m_sequenceId);
 }
 
 bool PdxFieldType::operator==(const PdxFieldType& other) const {
diff --git a/cppcache/src/PdxInstanceImpl.cpp b/cppcache/src/PdxInstanceImpl.cpp
index 387312a..5e52d67 100644
--- a/cppcache/src/PdxInstanceImpl.cpp
+++ b/cppcache/src/PdxInstanceImpl.cpp
@@ -788,10 +788,9 @@ int32_t PdxInstanceImpl::hashcode() const {
         break;
       }
       case PdxFieldTypes::UNKNOWN: {
-        char excpStr[256] = {0};
-        std::snprintf(excpStr, 256, "PdxInstance not found typeid %d ",
-                      static_cast<int>(pField->getTypeId()));
-        throw IllegalStateException(excpStr);
+        throw IllegalStateException(
+            std::string("PdxInstance not found typeid ") +
+            std::to_string(static_cast<int>(pField->getTypeId())));
       }
     }
   }
@@ -1319,10 +1318,9 @@ bool PdxInstanceImpl::operator==(const CacheableKey& 
other) const {
         break;
       }
       case PdxFieldTypes::UNKNOWN: {
-        char excpStr[256] = {0};
-        std::snprintf(excpStr, 256, "PdxInstance not found typeid  %d ",
-                      static_cast<int>(myPFT->getTypeId()));
-        throw IllegalStateException(excpStr);
+        throw IllegalStateException(
+            std::string("PdxInstance not found typeid ") +
+            std::to_string(static_cast<int>(myPFT->getTypeId())));
       }
     }
   }
diff --git a/cppcache/src/PutAllPartialResult.hpp 
b/cppcache/src/PutAllPartialResult.hpp
index 90c31c3..675fec6 100644
--- a/cppcache/src/PutAllPartialResult.hpp
+++ b/cppcache/src/PutAllPartialResult.hpp
@@ -85,33 +85,24 @@ class PutAllPartialResult final : public Serializable {
   bool hasSucceededKeys();
 
   virtual std::string toString() const final {
-    char msgStr1[1024];
-    if (m_firstFailedKey != nullptr) {
-      std::snprintf(msgStr1, 1024, "[ Key =%s ]",
-                    m_firstFailedKey->toString().c_str());
-    }
+    auto asString = std::string("PutAllPartialResult: [ Key =") +
+                    m_firstFailedKey->toString() + "]";
 
-    char msgStr2[1024];
     if (m_totalMapSize > 0) {
       // TODO:: impl. CacheableObjectPartList.size();
       int failedKeyNum = m_totalMapSize - m_succeededKeys->size();
       if (failedKeyNum > 0) {
-        std::snprintf(
-            msgStr2, 1024,
-            "The putAll operation failed to put %d out of %d entries ",
-            failedKeyNum, m_totalMapSize);
+        asString += "The putAll operation failed to put " +
+                    std::to_string(failedKeyNum) + " out of " +
+                    std::to_string(m_totalMapSize) + " entries ";
       } else {
-        std::snprintf(
-            msgStr2, 1024,
-            "The putAll operation successfully put %d out of %d entries ",
-            m_succeededKeys->size(), m_totalMapSize);
+        asString += "The putAll operation sucessfully put " +
+                    std::to_string(m_succeededKeys->size()) + " out of " +
+                    std::to_string(m_totalMapSize) + " entries ";
       }
     }
 
-    char stringBuf[7000];
-    std::snprintf(stringBuf, 7000, "PutAllPartialResult: %s%s", msgStr1,
-                  msgStr2);
-    return std::string(stringBuf);
+    return asString;
   }
 };
 
diff --git a/cppcache/src/RegionFactory.cpp b/cppcache/src/RegionFactory.cpp
index ffbaf57..4d0f20c 100644
--- a/cppcache/src/RegionFactory.cpp
+++ b/cppcache/src/RegionFactory.cpp
@@ -150,10 +150,8 @@ RegionFactory& RegionFactory::setRegionTimeToLive(
 }
 
 RegionFactory& RegionFactory::setInitialCapacity(int initialCapacity) {
-  char excpStr[256] = {0};
   if (initialCapacity < 0) {
-    std::snprintf(excpStr, 256, "initialCapacity must be >= 0 ");
-    throw IllegalArgumentException(excpStr);
+    throw IllegalArgumentException("initialCapacity must be >= 0");
   }
   m_regionAttributesFactory->setInitialCapacity(initialCapacity);
   return *this;
diff --git a/cppcache/src/RemoteQuery.cpp b/cppcache/src/RemoteQuery.cpp
index 5db516c..3612eac 100644
--- a/cppcache/src/RemoteQuery.cpp
+++ b/cppcache/src/RemoteQuery.cpp
@@ -100,12 +100,9 @@ std::shared_ptr<SelectResults> RemoteQuery::execute(
     sr = std::make_shared<ResultSetImpl>(values);
   } else {
     if (values->size() % fieldNameVec.size() != 0) {
-      char exMsg[1024];
-      std::snprintf(exMsg, 1023,
-                    "%s: Number of values coming from "
-                    "server has to be exactly divisible by field count",
-                    func);
-      throw MessageException(exMsg);
+      throw MessageException(std::string(func) +
+                             ": Number of values coming from server has to be "
+                             "exactly divisible by field count");
     } else {
       LOGFINEST("%s: creating StructSet for query: %s", func,
                 m_queryString.c_str());
diff --git a/cppcache/src/TcrMessage.cpp b/cppcache/src/TcrMessage.cpp
index c9632d7..6fc7b93 100644
--- a/cppcache/src/TcrMessage.cpp
+++ b/cppcache/src/TcrMessage.cpp
@@ -3177,12 +3177,8 @@ TcrMessageHelper::ChunkObjectType 
TcrMessageHelper::readChunkPartHeader(
     return ChunkObjectType::NULL_OBJECT;
   } else if (!isObj) {
     // otherwise we're currently always expecting an object
-    char exMsg[256];
-    std::snprintf(exMsg, sizeof(exMsg),
-                  "TcrMessageHelper::readChunkPartHeader: "
-                  "%s: part is not object",
-                  methodName);
-    LOGDEBUG("%s ", exMsg);
+    LOGDEBUG(std::string("TcrMessageHelper::readChunkPartHeader: ") +
+             methodName + ": part is not object");
     return ChunkObjectType::EXCEPTION;
   }
 
@@ -3198,26 +3194,21 @@ TcrMessageHelper::ChunkObjectType 
TcrMessageHelper::readChunkPartHeader(
       return ChunkObjectType::EXCEPTION;
     } else {
       char exMsg[256];
-      std::snprintf(exMsg, sizeof(exMsg),
-                    "TcrMessageHelper::readChunkPartHeader: %s: cannot handle "
-                    "java serializable object from server",
-                    methodName);
-      throw MessageException(exMsg);
+      throw MessageException(
+          std::string("TcrMessageHelper::readChunkPartHeader: ") + methodName +
+          ": cannot handle java serializable object from server");
     }
   } else if (partType == DSCode::NullObj) {
     // special null object is case for scalar query result
     return ChunkObjectType::NULL_OBJECT;
   }
 
-  // TODO enum - wtf?
   if (expectedFirstType > DSCode::FixedIDDefault) {
     if (partType != expectedFirstType) {
-      char exMsg[256];
-      std::snprintf(exMsg, sizeof(exMsg),
-                    "TcrMessageHelper::readChunkPartHeader: "
-                    "%s: got unhandled object class = %" PRId8,
-                    methodName, static_cast<int8_t>(partType));
-      throw MessageException(exMsg);
+      throw MessageException(
+          std::string("TcrMessageHelper::readChunkPartHeader: ") + methodName +
+          ": got unhandled object class = " +
+          std::to_string(static_cast<int8_t>(partType)));
     }
     // This is for GETALL
     if (expectedFirstType == DSCode::FixedIDShort) {
@@ -3228,12 +3219,11 @@ TcrMessageHelper::ChunkObjectType 
TcrMessageHelper::readChunkPartHeader(
     }
   }
   if (compId != expectedPartType) {
-    char exMsg[256];
-    std::snprintf(exMsg, sizeof(exMsg),
-                  "TcrMessageHelper::readChunkPartHeader: "
-                  "%s: got unhandled object type = %d, expected = %d, raw = 
%d",
-                  methodName, compId, expectedPartType, rawByte);
-    throw MessageException(exMsg);
+    throw MessageException(
+        std::string("TcrMessageHelper::readChunkPartHeader: ") + methodName +
+        ": got unhandled object type = " + std::to_string(compId) +
+        ", expected = " + std::to_string(expectedPartType) +
+        ", raw = " + std::to_string(static_cast<int>(rawByte)));
   }
   return ChunkObjectType::OBJECT;
 }
@@ -3249,12 +3239,9 @@ TcrMessageHelper::ChunkObjectType 
TcrMessageHelper::readChunkPartHeader(
     return ChunkObjectType::NULL_OBJECT;
   } else if (!isObj) {
     // otherwise we're currently always expecting an object
-    char exMsg[256];
-    std::snprintf(exMsg, 255,
-                  "TcrMessageHelper::readChunkPartHeader: "
-                  "%s: part is not object",
-                  methodName);
-    throw MessageException(exMsg);
+    throw MessageException(
+        std::string("TcrMessageHelper::readChunkPartHeader: ") + methodName +
+        ": part is not object");
   }
 
   const auto partType = static_cast<const DSCode>(input.read());
@@ -3265,12 +3252,9 @@ TcrMessageHelper::ChunkObjectType 
TcrMessageHelper::readChunkPartHeader(
       msg.setMessageType(TcrMessage::EXCEPTION);
       return ChunkObjectType::EXCEPTION;
     } else {
-      char exMsg[256];
-      std::snprintf(exMsg, 255,
-                    "TcrMessageHelper::readChunkPartHeader: %s: cannot handle "
-                    "java serializable object from server",
-                    methodName);
-      throw MessageException(exMsg);
+      throw MessageException(
+          std::string("TcrMessageHelper::readChunkPartHeader: ") + methodName +
+          ": cannot handle java serializable object from server");
     }
   } else if (partType == DSCode::NullObj) {
     // special null object is case for scalar query result
diff --git a/cppcache/src/ThinClientRegion.cpp 
b/cppcache/src/ThinClientRegion.cpp
index 1d96cb4..1030afd 100644
--- a/cppcache/src/ThinClientRegion.cpp
+++ b/cppcache/src/ThinClientRegion.cpp
@@ -3870,11 +3870,8 @@ void ChunkedDurableCQListResponse::handleChunk(const 
uint8_t* chunk,
   input.readInt32();
   if (!input.readBoolean()) {
     // we're currently always expecting an object
-    char exMsg[256];
-    std::snprintf(
-        exMsg, 255,
+    throw MessageException(
         "ChunkedDurableCQListResponse::handleChunk: part is not object");
-    throw MessageException(exMsg);
   }
 
   input.advanceCursor(1);  // skip the CacheableArrayList type ID byte
diff --git a/cppcache/src/Utils.cpp b/cppcache/src/Utils.cpp
index 5bbc806..86b7366 100644
--- a/cppcache/src/Utils.cpp
+++ b/cppcache/src/Utils.cpp
@@ -91,7 +91,7 @@ std::string Utils::convertHostToCanonicalForm(const char* 
endpoints) {
   std::string endpoint;
   std::string::size_type length = endpointsStr.size();
   std::string::size_type pos = 0;
-  ACE_TCHAR hostName[256], fullName[512];
+  ACE_TCHAR hostName[256];
   pos = endpointsStr.find(':', 0);
   if (pos != std::string::npos) {
     endpoint = endpointsStr.substr(0, pos);
@@ -114,8 +114,7 @@ std::string Utils::convertHostToCanonicalForm(const char* 
endpoints) {
     if (pos != std::string::npos) {
       ACE_INET_Addr addr(endpoints);
       addr.get_host_name(hostName, 256);
-      std::snprintf(fullName, sizeof(fullName), "%s:%d", hostName, port);
-      return fullName;
+      return std::string(hostName) + ":" + std::to_string(port);
     }
   }
   return endpoints;
diff --git a/cppcache/src/statistics/AtomicStatisticsImpl.cpp 
b/cppcache/src/statistics/AtomicStatisticsImpl.cpp
index 2ab27d3..927c006 100644
--- a/cppcache/src/statistics/AtomicStatisticsImpl.cpp
+++ b/cppcache/src/statistics/AtomicStatisticsImpl.cpp
@@ -135,11 +135,9 @@ void AtomicStatisticsImpl::close() {
 
 void AtomicStatisticsImpl::_setInt(int32_t offset, int32_t value) {
   if (offset >= statsType->getIntStatCount()) {
-    char s[128] = {'\0'};
-    std::snprintf(
-        s, 128, "setInt:The id (%d) of the Statistic Descriptor is not valid ",
-        offset);
-    throw IllegalArgumentException(s);
+    throw IllegalArgumentException(
+        "setInt:The id(" + std::to_string(offset) +
+        ") of the Statistic Descriptor is not valid");
   }
   intStorage[offset] = value;
 }
@@ -148,10 +146,9 @@ void AtomicStatisticsImpl::_setLong(int32_t offset, 
int64_t value) {
   if (offset >= statsType->getLongStatCount()) {
     char s[128] = {'\0'};
 
-    std::snprintf(
-        s, 128, "setLong:The id (%d) of the Statistic Descriptor is not valid 
",
-        offset);
-    throw IllegalArgumentException(s);
+    throw IllegalArgumentException(
+        "setLong:The id(" + std::to_string(offset) +
+        ") of the Statistic Descriptor is not valid");
   }
 
   longStorage[offset] = value;
@@ -159,12 +156,9 @@ void AtomicStatisticsImpl::_setLong(int32_t offset, 
int64_t value) {
 
 void AtomicStatisticsImpl::_setDouble(int32_t offset, double value) {
   if (offset >= statsType->getDoubleStatCount()) {
-    char s[128] = {'\0'};
-    std::snprintf(
-        s, 128,
-        "setDouble:The id (%d) of the Statistic Descriptor is not valid ",
-        offset);
-    throw IllegalArgumentException(s);
+    throw IllegalArgumentException(
+        "setDouble:The id(" + std::to_string(offset) +
+        ") of the Statistic Descriptor is not valid");
   }
 
   doubleStorage[offset] = value;
@@ -172,11 +166,9 @@ void AtomicStatisticsImpl::_setDouble(int32_t offset, 
double value) {
 
 int32_t AtomicStatisticsImpl::_getInt(int32_t offset) const {
   if (offset >= statsType->getIntStatCount()) {
-    char s[128] = {'\0'};
-    std::snprintf(
-        s, 128, "getInt:The id (%d) of the Statistic Descriptor is not valid ",
-        offset);
-    throw IllegalArgumentException(s);
+    throw IllegalArgumentException(
+        "getInt:The id(" + std::to_string(offset) +
+        ") of the Statistic Descriptor is not valid");
   }
 
   return intStorage[offset];
@@ -184,23 +176,18 @@ int32_t AtomicStatisticsImpl::_getInt(int32_t offset) 
const {
 
 int64_t AtomicStatisticsImpl::_getLong(int32_t offset) const {
   if (offset >= statsType->getLongStatCount()) {
-    char s[128] = {'\0'};
-    std::snprintf(
-        s, 128, "getLong:The id (%d) of the Statistic Descriptor is not valid 
",
-        offset);
-    throw IllegalArgumentException(s);
+    throw IllegalArgumentException(
+        "getLong:The id(" + std::to_string(offset) +
+        ") of the Statistic Descriptor is not valid");
   }
   return longStorage[offset];
 }
 
 double AtomicStatisticsImpl::_getDouble(int32_t offset) const {
   if (offset >= statsType->getDoubleStatCount()) {
-    char s[128] = {'\0'};
-    std::snprintf(
-        s, 128,
-        "getDouble:The id (%d) of the Statistic Descriptor is not valid ",
-        offset);
-    throw IllegalArgumentException(s);
+    throw IllegalArgumentException(
+        "getDouble:The id(" + std::to_string(offset) +
+        ") of the Statistic Descriptor is not valid");
   }
   return doubleStorage[offset];
 }
@@ -236,11 +223,9 @@ int64_t AtomicStatisticsImpl::getRawBits(
 
 int32_t AtomicStatisticsImpl::_incInt(int32_t offset, int32_t delta) {
   if (offset >= statsType->getIntStatCount()) {
-    char s[128] = {'\0'};
-    std::snprintf(
-        s, 128, "incInt:The id (%d) of the Statistic Descriptor is not valid ",
-        offset);
-    throw IllegalArgumentException(s);
+    throw IllegalArgumentException(
+        "incInt:The id(" + std::to_string(offset) +
+        ") of the Statistic Descriptor is not valid");
   }
 
   return (intStorage[offset] += delta);
diff --git a/cppcache/src/statistics/OsStatisticsImpl.cpp 
b/cppcache/src/statistics/OsStatisticsImpl.cpp
index a55b780..4634e35 100644
--- a/cppcache/src/statistics/OsStatisticsImpl.cpp
+++ b/cppcache/src/statistics/OsStatisticsImpl.cpp
@@ -154,34 +154,27 @@ void OsStatisticsImpl::close() {
 
 void OsStatisticsImpl::_setInt(int32_t offset, int32_t value) {
   if (offset >= statsType->getIntStatCount()) {
-    char s[128] = {'\0'};
-    std::snprintf(
-        s, 128, "setInt:The id (%d) of the Statistic Descriptor is not valid ",
-        offset);
-    throw IllegalArgumentException(s);
+    throw IllegalArgumentException(
+        "setInt:The id(" + std::to_string(offset) +
+        ") of the Statistic Descriptor is not valid");
   }
   intStorage[offset] = value;
 }
 
 void OsStatisticsImpl::_setLong(int32_t offset, int64_t value) {
   if (offset >= statsType->getLongStatCount()) {
-    char s[128] = {'\0'};
-    std::snprintf(
-        s, 128, "setLong:The id (%d) of the Statistic Descriptor is not valid 
",
-        offset);
-    throw IllegalArgumentException(s);
+    throw IllegalArgumentException(
+        "setLong:The id(" + std::to_string(offset) +
+        ") of the Statistic Descriptor is not valid");
   }
   longStorage[offset] = value;
 }
 
 void OsStatisticsImpl::_setDouble(int32_t offset, double value) {
   if (offset >= statsType->getDoubleStatCount()) {
-    char s[128] = {'\0'};
-    std::snprintf(
-        s, 128,
-        "setDouble:The id (%d) of the Statistic Descriptor is not valid ",
-        offset);
-    throw IllegalArgumentException(s);
+    throw IllegalArgumentException(
+        "setDouble:The id(" + std::to_string(offset) +
+        ") of the Statistic Descriptor is not valid");
   }
   doubleStorage[offset] = value;
 }
@@ -190,11 +183,9 @@ void OsStatisticsImpl::_setDouble(int32_t offset, double 
value) {
 
 int32_t OsStatisticsImpl::_getInt(int32_t offset) const {
   if (offset >= statsType->getIntStatCount()) {
-    char s[128] = {'\0'};
-    std::snprintf(
-        s, 128, "getInt:The id (%d) of the Statistic Descriptor is not valid ",
-        offset);
-    throw IllegalArgumentException(s);
+    throw IllegalArgumentException(
+        "getInt:The id(" + std::to_string(offset) +
+        ") of the Statistic Descriptor is not valid");
   }
 
   return intStorage[offset];
@@ -202,11 +193,9 @@ int32_t OsStatisticsImpl::_getInt(int32_t offset) const {
 
 int64_t OsStatisticsImpl::_getLong(int32_t offset) const {
   if (offset >= statsType->getLongStatCount()) {
-    char s[128] = {'\0'};
-    std::snprintf(
-        s, 128, "getLong:The id (%d) of the Statistic Descriptor is not valid 
",
-        offset);
-    throw IllegalArgumentException(s);
+    throw IllegalArgumentException(
+        "getLong:The id(" + std::to_string(offset) +
+        ") of the Statistic Descriptor is not valid");
   }
 
   return longStorage[offset];
@@ -214,12 +203,9 @@ int64_t OsStatisticsImpl::_getLong(int32_t offset) const {
 
 double OsStatisticsImpl::_getDouble(int32_t offset) const {
   if (offset >= statsType->getDoubleStatCount()) {
-    char s[128] = {'\0'};
-    std::snprintf(
-        s, 128,
-        "getDouble:The id (%d) of the Statistic Descriptor is not valid ",
-        offset);
-    throw IllegalArgumentException(s);
+    throw IllegalArgumentException(
+        "getDouble:The id(" + std::to_string(offset) +
+        ") of the Statistic Descriptor is not valid");
   }
 
   return doubleStorage[offset];
@@ -247,11 +233,9 @@ int64_t OsStatisticsImpl::_getRawBits(
 
 int32_t OsStatisticsImpl::_incInt(int32_t offset, int32_t delta) {
   if (offset >= statsType->getIntStatCount()) {
-    char s[128] = {'\0'};
-    std::snprintf(
-        s, 128, "incInt:The id (%d) of the Statistic Descriptor is not valid ",
-        offset);
-    throw IllegalArgumentException(s);
+    throw IllegalArgumentException(
+        "incInt:The id(" + std::to_string(offset) +
+        ") of the Statistic Descriptor is not valid");
   }
 
   intStorage[offset] += delta;
@@ -260,11 +244,9 @@ int32_t OsStatisticsImpl::_incInt(int32_t offset, int32_t 
delta) {
 
 int64_t OsStatisticsImpl::_incLong(int32_t offset, int64_t delta) {
   if (offset >= statsType->getLongStatCount()) {
-    char s[128] = {'\0'};
-    std::snprintf(
-        s, 128, "incLong:The id (%d) of the Statistic Descriptor is not valid 
",
-        offset);
-    throw IllegalArgumentException(s);
+    throw IllegalArgumentException(
+        "incLong:The id(" + std::to_string(offset) +
+        ") of the Statistic Descriptor is not valid");
   }
   longStorage[offset] += delta;
   return longStorage[offset];
@@ -272,12 +254,9 @@ int64_t OsStatisticsImpl::_incLong(int32_t offset, int64_t 
delta) {
 
 double OsStatisticsImpl::_incDouble(int32_t offset, double delta) {
   if (offset >= statsType->getDoubleStatCount()) {
-    char s[128] = {'\0'};
-    std::snprintf(
-        s, 128,
-        "incDouble:The id (%d) of the Statistic Descriptor is not valid ",
-        offset);
-    throw IllegalArgumentException(s);
+    throw IllegalArgumentException(
+        "incDouble:The id(" + std::to_string(offset) +
+        ") of the Statistic Descriptor is not valid");
   }
   doubleStorage[offset] += delta;
   return doubleStorage[offset];
diff --git a/sqliteimpl/SqLiteHelper.cpp b/sqliteimpl/SqLiteHelper.cpp
index 06555fb..8c37415 100644
--- a/sqliteimpl/SqLiteHelper.cpp
+++ b/sqliteimpl/SqLiteHelper.cpp
@@ -19,8 +19,6 @@
 
 #include <string.h>
 
-#define QUERY_SIZE 512
-
 int SqLiteHelper::initDB(const char* regionName, int maxPageCount, int 
pageSize,
                          const char* regionDBfile, int busy_timeout_ms) {
   // open the database
@@ -48,15 +46,13 @@ int SqLiteHelper::initDB(const char* regionName, int 
maxPageCount, int pageSize,
 
 int SqLiteHelper::createTable() {
   // construct query
-  char query[QUERY_SIZE];
-  SNPRINTF(query, QUERY_SIZE,
-           "CREATE TABLE IF NOT EXISTS %s(key BLOB PRIMARY KEY,value BLOB);",
-           m_tableName);
+  auto query = std::string("CREATE TABLE IF NOT EXISTS ") + m_tableName +
+               "(key BLOB PRIMARY KEY, value BLOB);";
   sqlite3_stmt* stmt;
 
   // prepare statement
   int retCode;
-  retCode = sqlite3_prepare_v2(m_dbHandle, query, -1, &stmt, nullptr);
+  retCode = sqlite3_prepare_v2(m_dbHandle, query.c_str(), -1, &stmt, nullptr);
 
   // execute statement
   if (retCode == SQLITE_OK) retCode = sqlite3_step(stmt);
@@ -67,12 +63,12 @@ int SqLiteHelper::createTable() {
 int SqLiteHelper::insertKeyValue(void* keyData, int keyDataSize,
                                  void* valueData, int valueDataSize) {
   // construct query
-  char query[QUERY_SIZE];
-  SNPRINTF(query, QUERY_SIZE, "REPLACE INTO %s VALUES(?,?);", m_tableName);
+  auto query = std::string("REPLACE INTO ") + m_tableName + " VALUES(?,?);";
 
   // prepare statement
   sqlite3_stmt* stmt;
-  int retCode = sqlite3_prepare_v2(m_dbHandle, query, -1, &stmt, nullptr);
+  int retCode =
+      sqlite3_prepare_v2(m_dbHandle, query.c_str(), -1, &stmt, nullptr);
   if (retCode == SQLITE_OK) {
     // bind parameters and execte statement
     sqlite3_bind_blob(stmt, 1, keyData, keyDataSize, nullptr);
@@ -86,12 +82,12 @@ int SqLiteHelper::insertKeyValue(void* keyData, int 
keyDataSize,
 
 int SqLiteHelper::removeKey(void* keyData, int keyDataSize) {
   // construct query
-  char query[QUERY_SIZE];
-  SNPRINTF(query, QUERY_SIZE, "DELETE FROM %s WHERE key=?;", m_tableName);
+  auto query = std::string("DELETE FROM ") + m_tableName + " WHERE key=?;";
 
   // prepare statement
   sqlite3_stmt* stmt;
-  int retCode = sqlite3_prepare_v2(m_dbHandle, query, -1, &stmt, nullptr);
+  int retCode =
+      sqlite3_prepare_v2(m_dbHandle, query.c_str(), -1, &stmt, nullptr);
   if (retCode == SQLITE_OK) {
     // bind parameters and execte statement
     sqlite3_bind_blob(stmt, 1, keyData, keyDataSize, nullptr);
@@ -105,14 +101,13 @@ int SqLiteHelper::removeKey(void* keyData, int 
keyDataSize) {
 int SqLiteHelper::getValue(void* keyData, int keyDataSize, void*& valueData,
                            int& valueDataSize) {
   // construct query
-  char query[QUERY_SIZE];
-  SNPRINTF(query, QUERY_SIZE,
-           "SELECT value, length(value) AS valLength FROM %s WHERE key=?;",
-           m_tableName);
+  auto query = std::string("SELECT value, length(value) AS valLength FROM ") +
+               m_tableName + " WHERE key=?;";
 
   // prepare statement
   sqlite3_stmt* stmt;
-  int retCode = sqlite3_prepare_v2(m_dbHandle, query, -1, &stmt, nullptr);
+  int retCode =
+      sqlite3_prepare_v2(m_dbHandle, query.c_str(), -1, &stmt, nullptr);
   if (retCode == SQLITE_OK) {
     // bind parameters and execte statement
     sqlite3_bind_blob(stmt, 1, keyData, keyDataSize, nullptr);
@@ -134,13 +129,12 @@ int SqLiteHelper::getValue(void* keyData, int 
keyDataSize, void*& valueData,
 
 int SqLiteHelper::dropTable() {
   // create query
-  char query[QUERY_SIZE];
-  SNPRINTF(query, QUERY_SIZE, "DROP TABLE %s;", m_tableName);
+  auto query = std::string("DROP TABLE ") + m_tableName + ";";
 
   // prepare statement
   sqlite3_stmt* stmt;
   int retCode;
-  retCode = sqlite3_prepare_v2(m_dbHandle, query, -1, &stmt, nullptr);
+  retCode = sqlite3_prepare_v2(m_dbHandle, query.c_str(), -1, &stmt, nullptr);
 
   // execute statement
   if (retCode == SQLITE_OK) retCode = sqlite3_step(stmt);
@@ -158,15 +152,13 @@ int SqLiteHelper::closeDB() {
 
 int SqLiteHelper::executePragma(const char* pragmaName, int pragmaValue) {
   // create query
-  char query[QUERY_SIZE];
-  char strVal[50];
-  SNPRINTF(strVal, 50, "%d", pragmaValue);
-  SNPRINTF(query, QUERY_SIZE, "PRAGMA %s = %s;", pragmaName, strVal);
+  auto query = std::string("PRAGMA ") + pragmaName + " = " +
+               std::to_string(pragmaValue) + ";";
 
   // prepare statement
   sqlite3_stmt* stmt;
   int retCode;
-  retCode = sqlite3_prepare_v2(m_dbHandle, query, -1, &stmt, nullptr);
+  retCode = sqlite3_prepare_v2(m_dbHandle, query.c_str(), -1, &stmt, nullptr);
 
   // execute PRAGMA
   if (retCode == SQLITE_OK &&
diff --git a/sqliteimpl/SqLiteHelper.hpp b/sqliteimpl/SqLiteHelper.hpp
index 3fea892..f5348d3 100644
--- a/sqliteimpl/SqLiteHelper.hpp
+++ b/sqliteimpl/SqLiteHelper.hpp
@@ -29,12 +29,6 @@
 #include <sys/stat.h>
 #endif
 
-#ifdef _WIN32
-#define SNPRINTF _snprintf
-#else
-#define SNPRINTF snprintf
-#endif
-
 class SqLiteHelper {
  public:
   int initDB(const char* regionName, int maxPageCount, int pageSize,
@@ -50,7 +44,6 @@ class SqLiteHelper {
   sqlite3* m_dbHandle;
 
   const char* m_tableName;
-  // std::string regionName;
   int dropTable();
   int createTable();
   int executePragma(const char* pragmaName, int pragmaValue);
diff --git a/tests/cpp/testobject/Portfolio.cpp 
b/tests/cpp/testobject/Portfolio.cpp
index b711ef5..7b6784c 100644
--- a/tests/cpp/testobject/Portfolio.cpp
+++ b/tests/cpp/testobject/Portfolio.cpp
@@ -16,116 +16,102 @@
  */
 #include "Portfolio.hpp"
 
-namespace testobject {
+#include <sstream>
 
-const char* Portfolio::secIds[] = {"SUN", "IBM",  "YHOO", "GOOG", "MSFT",
-                                   "AOL", "APPL", "ORCL", "SAP",  "DELL"};
+namespace testobject {
+const char* Portfolio::_secIds[] = {"SUN", "IBM",  "YHOO", "GOOG", "MSFT",
+                                    "AOL", "APPL", "ORCL", "SAP",  "DELL"};
 
 Portfolio::Portfolio(int32_t i, uint32_t size,
                      std::shared_ptr<CacheableStringArray> nm)
-    : names(nm) {
-  ID = i;
-  char pkidbuf[1024];
-  sprintf(pkidbuf, "%d", i);
-  pkid = CacheableString::create(pkidbuf);
-  status = (i % 2 == 0) ? "active" : "inactive";
-  char buf[100];
-  sprintf(buf, "type%d", (i % 3));
-  type = CacheableString::create(buf);
-  int numSecIds = sizeof(secIds) / sizeof(char*);
-  position1 = std::make_shared<Position>(secIds[Position::cnt % numSecIds],
-                                         Position::cnt * 1000);
+    : _names(nm) {
+  _ID = i;
+  _pkid = CacheableString::create(std::to_string(i));
+  _status = (i % 2 == 0) ? "active" : "inactive";
+  _type = CacheableString::create("_type" + std::to_string(i % 3));
+  int numSecIds = sizeof(_secIds) / sizeof(char*);
+  _position1 = std::make_shared<Position>(_secIds[Position::cnt % numSecIds],
+                                          Position::cnt * 1000);
   if (i % 2 != 0) {
-    position2 = std::make_shared<Position>(secIds[Position::cnt % numSecIds],
-                                           Position::cnt * 1000);
+    _position2 = std::make_shared<Position>(_secIds[Position::cnt % numSecIds],
+                                            Position::cnt * 1000);
   } else {
-    position2 = nullptr;
+    _position2 = nullptr;
   }
-  positions = CacheableHashMap::create();
-  positions->emplace(CacheableString::create(secIds[Position::cnt % 
numSecIds]),
-                     position1);
-  newVal = new uint8_t[size + 1];
-  memset(newVal, 'B', size);
-  newVal[size] = '\0';
-  newValSize = size;
-  creationDate = CacheableDate::create(time(nullptr));
-  arrayNull = nullptr;
-  arrayZeroSize = nullptr;
+  _positions = CacheableHashMap::create();
+  _positions->emplace(
+      CacheableString::create(_secIds[Position::cnt % numSecIds]), _position1);
+  _newVal = new uint8_t[size + 1];
+  memset(_newVal, 'B', size);
+  _newVal[size] = '\0';
+  _newValSize = size;
+  _creationDate = CacheableDate::create(time(nullptr));
+  _arrayNull = nullptr;
+  _arrayZeroSize = nullptr;
 }
 
 Portfolio::~Portfolio() noexcept {
-  if (newVal) {
-    delete[] newVal;
-    newVal = nullptr;
+  if (_newVal) {
+    delete[] _newVal;
+    _newVal = nullptr;
   }
 }
 
 void Portfolio::toData(DataOutput& output) const {
-  output.writeInt(ID);
-  output.writeObject(pkid);
-  output.writeObject(position1);
-  output.writeObject(position2);
-  output.writeObject(positions);
-  output.writeObject(type);
-  output.writeUTF(status);
-  output.writeObject(names);
-  output.writeBytes(newVal, newValSize + 1);
-  output.writeObject(creationDate);
-  output.writeBytes(arrayNull, 0);
-  output.writeBytes(arrayZeroSize, 0);
+  output.writeInt(_ID);
+  output.writeObject(_pkid);
+  output.writeObject(_position1);
+  output.writeObject(_position2);
+  output.writeObject(_positions);
+  output.writeObject(_type);
+  output.writeUTF(_status);
+  output.writeObject(_names);
+  output.writeBytes(_newVal, _newValSize + 1);
+  output.writeObject(_creationDate);
+  output.writeBytes(_arrayNull, 0);
+  output.writeBytes(_arrayZeroSize, 0);
 }
 
 void Portfolio::fromData(DataInput& input) {
-  ID = input.readInt32();
-  pkid = std::dynamic_pointer_cast<CacheableString>(input.readObject());
-  position1 = std::dynamic_pointer_cast<Position>(input.readObject());
-  position2 = std::dynamic_pointer_cast<Position>(input.readObject());
-  positions = std::dynamic_pointer_cast<CacheableHashMap>(input.readObject());
-  type = std::dynamic_pointer_cast<CacheableString>(input.readObject());
-  status = input.readUTF();
-  names = std::dynamic_pointer_cast<CacheableStringArray>(input.readObject());
-  input.readBytes(&newVal, &newValSize);
-  creationDate = std::dynamic_pointer_cast<CacheableDate>(input.readObject());
+  _ID = input.readInt32();
+  _pkid = std::dynamic_pointer_cast<CacheableString>(input.readObject());
+  _position1 = std::dynamic_pointer_cast<Position>(input.readObject());
+  _position2 = std::dynamic_pointer_cast<Position>(input.readObject());
+  _positions = std::dynamic_pointer_cast<CacheableHashMap>(input.readObject());
+  _type = std::dynamic_pointer_cast<CacheableString>(input.readObject());
+  _status = input.readUTF();
+  _names = std::dynamic_pointer_cast<CacheableStringArray>(input.readObject());
+  input.readBytes(&_newVal, &_newValSize);
+  _creationDate = std::dynamic_pointer_cast<CacheableDate>(input.readObject());
   int tmp = 0;
-  input.readBytes(&arrayNull, &tmp);
-  input.readBytes(&arrayZeroSize, &tmp);
+  input.readBytes(&_arrayNull, &tmp);
+  input.readBytes(&_arrayZeroSize, &tmp);
 }
+
 std::string Portfolio::toString() const {
-  char idbuf[1024];
-  sprintf(idbuf, "PortfolioObject: [ ID=%d", ID);
-  char pkidbuf[1024];
-  if (pkid != nullptr) {
-    sprintf(pkidbuf, " status=%s type=%s pkid=%s\n", this->status.c_str(),
-            this->type->toString().c_str(), this->pkid->value().c_str());
-  } else {
-    sprintf(pkidbuf, " status=%s type=%s pkid=%s\n", this->status.c_str(),
-            this->type->toString().c_str(), this->pkid->value().c_str());
-  }
-  char position1buf[2048];
-  if (position1 != nullptr) {
-    sprintf(position1buf, "\t\t\t  P1: %s", position1->toString().c_str());
-  } else {
-    sprintf(position1buf, "\t\t\t  P1: %s", "NULL");
-  }
-  char position2buf[2048];
-  if (position2 != nullptr) {
-    snprintf(position2buf, sizeof(position2buf), " P2: %s",
-             position2->toString().c_str());
-  } else {
-    snprintf(position2buf, sizeof(position2buf), " P2: %s ]", "NULL");
-  }
-  char creationdatebuf[2048];
-  if (creationDate != nullptr) {
-    sprintf(creationdatebuf, "creation Date %s",
-            creationDate->toString().c_str());
-  } else {
-    sprintf(creationdatebuf, "creation Date %s", "NULL");
-  }
+  std::stringstream result;
+  auto suffix = "\n    ";
+
+  result << "PortfolioObject: [" << suffix;
+
+  result << "ID = " << _ID << suffix;
+
+  result << " status=" << _status << suffix;
+
+  result << " type=" << (_type ? _type->toString() : "NULL") << suffix;
+
+  result << " pkid=" << (_pkid ? _pkid->toString() : "NULL") << suffix;
+
+  result << " creation Date="
+         << (_creationDate ? _creationDate->toString() : "NULL") << suffix;
+
+  result << "P1: " << (_position1 ? _position1->toString() : "NULL") << suffix;
+
+  result << "P2: " << (_position2 ? _position2->toString() : "NULL") << "\n";
+
+  result << "]";
 
-  char stringBuf[9000];
-  snprintf(stringBuf, sizeof(stringBuf), "%.1024s%.1024s%.1024s%.2048s%.2048s",
-           idbuf, pkidbuf, creationdatebuf, position1buf, position2buf);
-  return stringBuf;
+  return result.str();
 }
 
 }  // namespace testobject
diff --git a/tests/cpp/testobject/Portfolio.hpp 
b/tests/cpp/testobject/Portfolio.hpp
index e551c98..56045c2 100644
--- a/tests/cpp/testobject/Portfolio.hpp
+++ b/tests/cpp/testobject/Portfolio.hpp
@@ -39,20 +39,20 @@ using apache::geode::client::CacheableStringArray;
 
 class TESTOBJECT_EXPORT Portfolio : public DataSerializable {
  private:
-  int32_t ID;
-  std::shared_ptr<CacheableString> pkid;
-  std::shared_ptr<Position> position1;
-  std::shared_ptr<Position> position2;
-  std::shared_ptr<CacheableHashMap> positions;
-  std::shared_ptr<CacheableString> type;
-  std::string status;
-  std::shared_ptr<CacheableStringArray> names;
-  static const char* secIds[];
-  uint8_t* newVal;
-  int32_t newValSize;
-  std::shared_ptr<CacheableDate> creationDate;
-  uint8_t* arrayNull;
-  uint8_t* arrayZeroSize;
+  int32_t _ID;
+  std::shared_ptr<CacheableString> _pkid;
+  std::shared_ptr<Position> _position1;
+  std::shared_ptr<Position> _position2;
+  std::shared_ptr<CacheableHashMap> _positions;
+  std::shared_ptr<CacheableString> _type;
+  std::string _status;
+  std::shared_ptr<CacheableStringArray> _names;
+  static const char* _secIds[];
+  uint8_t* _newVal;
+  int32_t _newValSize;
+  std::shared_ptr<CacheableDate> _creationDate;
+  uint8_t* _arrayNull;
+  uint8_t* _arrayZeroSize;
 
   inline size_t getObjectSize(const std::shared_ptr<Serializable>& obj) const {
     return (obj == nullptr ? 0 : obj->objectSize());
@@ -60,69 +60,69 @@ class TESTOBJECT_EXPORT Portfolio : public DataSerializable 
{
 
  public:
   Portfolio()
-      : ID(0),
-        pkid(nullptr),
-        type(nullptr),
-        status(),
-        newVal(nullptr),
-        creationDate(nullptr),
-        arrayNull(nullptr),
-        arrayZeroSize(nullptr) {}
+      : _ID(0),
+        _pkid(nullptr),
+        _type(nullptr),
+        _status(),
+        _newVal(nullptr),
+        _creationDate(nullptr),
+        _arrayNull(nullptr),
+        _arrayZeroSize(nullptr) {}
   explicit Portfolio(int32_t id, uint32_t size = 0,
                      std::shared_ptr<CacheableStringArray> nm = nullptr);
   ~Portfolio() noexcept override;
 
   size_t objectSize() const override {
     auto objectSize = sizeof(Portfolio);
-    objectSize += getObjectSize(pkid);
-    objectSize += getObjectSize(position1);
-    objectSize += getObjectSize(position2);
-    objectSize += getObjectSize(positions);
-    objectSize += getObjectSize(type);
-    objectSize += sizeof(decltype(status)::value_type) * status.length();
-    objectSize += getObjectSize(names);
-    objectSize += sizeof(uint8_t) * newValSize;
-    objectSize += getObjectSize(creationDate);
+    objectSize += getObjectSize(_pkid);
+    objectSize += getObjectSize(_position1);
+    objectSize += getObjectSize(_position2);
+    objectSize += getObjectSize(_positions);
+    objectSize += getObjectSize(_type);
+    objectSize += sizeof(decltype(_status)::value_type) * _status.length();
+    objectSize += getObjectSize(_names);
+    objectSize += sizeof(uint8_t) * _newValSize;
+    objectSize += getObjectSize(_creationDate);
     return objectSize;
   }
 
-  int32_t getID() { return ID; }
+  int32_t getID() { return _ID; }
   void showNames(const char* label) {
     LOGINFO(label);
-    if (!names) {
+    if (!_names) {
       LOGINFO("names is NULL");
       return;
     }
-    for (int i = 0; i < names->length(); i++) {
-      LOGINFO("names[%d]=%s", i, names->operator[](i)->value().c_str());
+    for (int i = 0; i < _names->length(); i++) {
+      LOGINFO("names[%d]=%s", i, _names->operator[](i)->value().c_str());
     }
   }
 
-  std::shared_ptr<CacheableString> getPkid() const { return pkid; }
+  std::shared_ptr<CacheableString> getPkid() const { return _pkid; }
 
-  std::shared_ptr<Position> getP1() const { return position1; }
+  std::shared_ptr<Position> getP1() const { return _position1; }
 
-  std::shared_ptr<Position> getP2() const { return position2; }
+  std::shared_ptr<Position> getP2() const { return _position2; }
 
-  std::shared_ptr<CacheableHashMap> getPositions() const { return positions; }
+  std::shared_ptr<CacheableHashMap> getPositions() const { return _positions; }
 
   bool testMethod() const { return true; }
 
-  const std::string& getStatus() const { return status; }
+  const std::string& getStatus() const { return _status; }
 
-  bool isActive() const { return status == "active"; }
+  bool isActive() const { return _status == "active"; }
 
-  uint8_t* getNewVal() const { return newVal; }
+  uint8_t* getNewVal() const { return _newVal; }
 
-  int32_t getNewValSize() const { return newValSize; }
+  int32_t getNewValSize() const { return _newValSize; }
 
   std::shared_ptr<CacheableDate> getCreationDate() const {
-    return creationDate;
+    return _creationDate;
   }
 
-  uint8_t* getArrayNull() const { return arrayNull; }
+  uint8_t* getArrayNull() const { return _arrayNull; }
 
-  uint8_t* getArrayZeroSize() const { return arrayZeroSize; }
+  uint8_t* getArrayZeroSize() const { return _arrayZeroSize; }
 
   static std::shared_ptr<Serializable> createDeserializable() {
     return std::make_shared<Portfolio>();
diff --git a/tests/cpp/testobject/PortfolioPdx.cpp 
b/tests/cpp/testobject/PortfolioPdx.cpp
index ba2c79a..859d4b3 100644
--- a/tests/cpp/testobject/PortfolioPdx.cpp
+++ b/tests/cpp/testobject/PortfolioPdx.cpp
@@ -16,140 +16,131 @@
  */
 #include "PortfolioPdx.hpp"
 
+#include <sstream>
 #include <util/Log.hpp>
 
 namespace testobject {
-
 using apache::geode::client::CacheableDate;
 using apache::geode::client::CacheableHashMap;
 using apache::geode::client::CacheableString;
 
-const char* PortfolioPdx::secIds[] = {"SUN", "IBM",  "YHOO", "GOOG", "MSFT",
-                                      "AOL", "APPL", "ORCL", "SAP",  "DELL"};
+const char* PortfolioPdx::_secIds[] = {"SUN", "IBM",  "YHOO", "GOOG", "MSFT",
+                                       "AOL", "APPL", "ORCL", "SAP",  "DELL"};
 
 PortfolioPdx::PortfolioPdx(int32_t i, int32_t size, std::vector<std::string> 
nm)
-    : names(nm) {
-  id = i;
+    : _names(nm) {
+  _id = i;
 
-  pkid = std::to_string(i);
+  _pkid = std::to_string(i);
 
-  status = (i % 2 == 0) ? "active" : "inactive";
+  _status = (i % 2 == 0) ? "active" : "inactive";
 
-  type = "type" + std::to_string(i % 3);
+  _type = "_type" + std::to_string(i % 3);
 
-  int numSecIds = sizeof(secIds) / sizeof(char*);
-  position1 = std::make_shared<PositionPdx>(
-      secIds[PositionPdx::cnt % numSecIds], PositionPdx::cnt * 1000);
+  int numSecIds = sizeof(_secIds) / sizeof(char*);
+  _position1 = std::make_shared<PositionPdx>(
+      _secIds[PositionPdx::cnt % numSecIds], PositionPdx::cnt * 1000);
   if (i % 2 != 0) {
-    position2 = std::make_shared<PositionPdx>(
-        secIds[PositionPdx::cnt % numSecIds], PositionPdx::cnt * 1000);
+    _position2 = std::make_shared<PositionPdx>(
+        _secIds[PositionPdx::cnt % numSecIds], PositionPdx::cnt * 1000);
   } else {
-    position2 = nullptr;
+    _position2 = nullptr;
   }
-  positions = CacheableHashMap::create();
-  positions->emplace(
-      CacheableString::create(secIds[PositionPdx::cnt % numSecIds]), 
position1);
+  _positions = CacheableHashMap::create();
+  _positions->emplace(
+      CacheableString::create(_secIds[PositionPdx::cnt % numSecIds]),
+      _position1);
 
   if (size > 0) {
-    newVal = std::vector<int8_t>(size);
+    _newVal = std::vector<int8_t>(size);
     for (int index = 0; index < size; index++) {
-      newVal[index] = static_cast<int8_t>('B');
+      _newVal[index] = static_cast<int8_t>('B');
     }
   }
-  newValSize = size;
+  _newValSize = size;
 
   time_t timeVal = 1310447869;
-  creationDate = CacheableDate::create(timeVal);
-  arrayZeroSize = std::vector<int8_t>(0);
+  _creationDate = CacheableDate::create(timeVal);
+  _arrayZeroSize = std::vector<int8_t>(0);
 }
 
 void PortfolioPdx::toData(PdxWriter& pw) const {
-  pw.writeInt("ID", id);
+  pw.writeInt("ID", _id);
   pw.markIdentityField("ID");
 
-  pw.writeString("pkid", pkid);
+  pw.writeString("pkid", _pkid);
   pw.markIdentityField("pkid");
 
-  pw.writeObject("position1", position1);
+  pw.writeObject("position1", _position1);
   pw.markIdentityField("position1");
 
-  pw.writeObject("position2", position2);
+  pw.writeObject("position2", _position2);
   pw.markIdentityField("position2");
 
-  pw.writeObject("positions", positions);
+  pw.writeObject("positions", _positions);
   pw.markIdentityField("positions");
 
-  pw.writeString("type", type);
+  pw.writeString("type", _type);
   pw.markIdentityField("type");
 
-  pw.writeString("status", status);
+  pw.writeString("status", _status);
   pw.markIdentityField("status");
 
-  pw.writeStringArray("names", names);
+  pw.writeStringArray("names", _names);
   pw.markIdentityField("names");
 
-  pw.writeByteArray("newVal", newVal);
+  pw.writeByteArray("newVal", _newVal);
   pw.markIdentityField("newVal");
 
-  pw.writeDate("creationDate", creationDate);
+  pw.writeDate("creationDate", _creationDate);
   pw.markIdentityField("creationDate");
 
-  pw.writeByteArray("arrayNull", arrayNull);
-  pw.writeByteArray("arrayZeroSize", arrayZeroSize);
+  pw.writeByteArray("arrayNull", _arrayNull);
+  pw.writeByteArray("arrayZeroSize", _arrayZeroSize);
 }
 
 void PortfolioPdx::fromData(PdxReader& pr) {
-  id = pr.readInt("ID");
-  pkid = pr.readString("pkid");
+  _id = pr.readInt("ID");
+  _pkid = pr.readString("pkid");
 
-  position1 =
+  _position1 =
       std::dynamic_pointer_cast<PositionPdx>(pr.readObject("position1"));
-  position2 =
+  _position2 =
       std::dynamic_pointer_cast<PositionPdx>(pr.readObject("position2"));
-  positions =
+  _positions =
       std::dynamic_pointer_cast<CacheableHashMap>(pr.readObject("positions"));
-  type = pr.readString("type");
-  status = pr.readString("status");
-
-  names = pr.readStringArray("names");
-  newVal = pr.readByteArray("newVal");
-  creationDate = pr.readDate("creationDate");
-  arrayNull = pr.readByteArray("arrayNull");
-  arrayZeroSize = pr.readByteArray("arrayZeroSize");
+  _type = pr.readString("type");
+  _status = pr.readString("status");
+
+  _names = pr.readStringArray("names");
+  _newVal = pr.readByteArray("newVal");
+  _creationDate = pr.readDate("creationDate");
+  _arrayNull = pr.readByteArray("arrayNull");
+  _arrayZeroSize = pr.readByteArray("arrayZeroSize");
 }
 std::string PortfolioPdx::toString() const {
-  LOGINFO("PortfolioPdx::toString() Start");
-  char idbuf[1024];
-  sprintf(idbuf, "PortfolioPdxObject: [ id=%d ]", id);
+  std::stringstream result;
+  auto suffix = "\n    ";
+  result << "PortfolioPdxObject: [" << suffix;
 
-  char pkidbuf[1024];
-  sprintf(pkidbuf, " status=%s type=%s pkid=%s\n", this->status.c_str(),
-          this->type.c_str(), this->pkid.c_str());
+  result << "id = " << _id << suffix;
 
-  char position1buf[2048];
-  if (position1 != nullptr) {
-    sprintf(position1buf, "\t\t\t  P1: %s", position1->toString().c_str());
-  } else {
-    sprintf(position1buf, "\t\t\t  P1: %s", "NULL");
-  }
-  char position2buf[2048];
-  if (position2 != nullptr) {
-    sprintf(position2buf, " P2: %s", position2->toString().c_str());
-  } else {
-    sprintf(position2buf, " P2: %s ]", "NULL");
-  }
-  char creationdatebuf[2048];
-  if (creationDate != nullptr) {
-    sprintf(creationdatebuf, "creation Date %s",
-            creationDate->toString().c_str());
-  } else {
-    sprintf(creationdatebuf, "creation Date %s", "NULL");
-  }
+  result << "status=" << _status << suffix;
+
+  result << "type=" << _type << suffix;
+
+  result << "pkid=" << _pkid << suffix;
+
+  result << "creation Date="
+         << (_creationDate ? _creationDate->toString() : "NULL") << suffix;
+
+  result << "P1: " << (_position1 ? _position1->toString() : "NULL") << suffix;
+
+  result << "P2: " << (_position2 ? _position2->toString() : "NULL") << "\n";
+
+  result << "]";
 
-  char stringBuf[9000];
-  snprintf(stringBuf, sizeof(stringBuf), "%s%s%s%s%s", idbuf, pkidbuf,
-           creationdatebuf, position1buf, position2buf);
-  return stringBuf;
+  return result.str();
 }
 
 }  // namespace testobject
diff --git a/tests/cpp/testobject/PortfolioPdx.hpp 
b/tests/cpp/testobject/PortfolioPdx.hpp
index c1f9ed6..bcb4f42 100644
--- a/tests/cpp/testobject/PortfolioPdx.hpp
+++ b/tests/cpp/testobject/PortfolioPdx.hpp
@@ -27,71 +27,70 @@
 #include "PositionPdx.hpp"
 
 namespace testobject {
-
 using apache::geode::client::CacheableDate;
 using apache::geode::client::CacheableHashMap;
 using apache::geode::client::PdxSerializable;
 
 class TESTOBJECT_EXPORT PortfolioPdx : public PdxSerializable {
  private:
-  int32_t id;
-
-  std::string pkid;
-
-  std::shared_ptr<PositionPdx> position1;
-  std::shared_ptr<PositionPdx> position2;
-  std::shared_ptr<CacheableHashMap> positions;
-  std::string type;
-  std::string status;
-  std::vector<std::string> names;
-  static const char* secIds[];
-  std::vector<int8_t> newVal;
-  int32_t newValSize;
-  std::shared_ptr<CacheableDate> creationDate;
-  std::vector<int8_t> arrayNull;
-  std::vector<int8_t> arrayZeroSize;
+  int32_t _id;
+
+  std::string _pkid;
+
+  std::shared_ptr<PositionPdx> _position1;
+  std::shared_ptr<PositionPdx> _position2;
+  std::shared_ptr<CacheableHashMap> _positions;
+  std::string _type;
+  std::string _status;
+  std::vector<std::string> _names;
+  static const char* _secIds[];
+  std::vector<int8_t> _newVal;
+  int32_t _newValSize;
+  std::shared_ptr<CacheableDate> _creationDate;
+  std::vector<int8_t> _arrayNull;
+  std::vector<int8_t> _arrayZeroSize;
 
  public:
   PortfolioPdx()
-      : id(0),
-        pkid(),
-        type(),
-        status(),
-        newVal(),
-        creationDate(nullptr),
-        arrayNull(),
-        arrayZeroSize() {}
+      : _id(0),
+        _pkid(),
+        _type(),
+        _status(),
+        _newVal(),
+        _creationDate(nullptr),
+        _arrayNull(),
+        _arrayZeroSize() {}
 
   explicit PortfolioPdx(int32_t id, int32_t size = 0,
                         std::vector<std::string> nm = {});
 
-  int32_t getID() { return id; }
+  int32_t getID() { return _id; }
 
-  std::string getPkid() { return pkid; }
+  std::string getPkid() { return _pkid; }
 
-  std::shared_ptr<PositionPdx> getP1() { return position1; }
+  std::shared_ptr<PositionPdx> getP1() { return _position1; }
 
-  std::shared_ptr<PositionPdx> getP2() { return position2; }
+  std::shared_ptr<PositionPdx> getP2() { return _position2; }
 
-  std::shared_ptr<CacheableHashMap> getPositions() { return positions; }
+  std::shared_ptr<CacheableHashMap> getPositions() { return _positions; }
 
   bool testMethod() { return true; }
 
-  const std::string& getStatus() { return status; }
+  const std::string& getStatus() { return _status; }
 
-  bool isActive() { return status == "active"; }
+  bool isActive() { return _status == "active"; }
 
-  std::vector<int8_t> getNewVal() { return newVal; }
+  std::vector<int8_t> getNewVal() { return _newVal; }
 
-  int32_t getNewValSize() { return newValSize; }
+  int32_t getNewValSize() { return _newValSize; }
 
-  const std::string& getClassName() { return this->type; }
+  const std::string& getClassName() { return this->_type; }
 
-  std::shared_ptr<CacheableDate> getCreationDate() { return creationDate; }
+  std::shared_ptr<CacheableDate> getCreationDate() { return _creationDate; }
 
-  std::vector<int8_t> getArrayNull() { return arrayNull; }
+  std::vector<int8_t> getArrayNull() { return _arrayNull; }
 
-  std::vector<int8_t> getArrayZeroSize() { return arrayZeroSize; }
+  std::vector<int8_t> getArrayZeroSize() { return _arrayZeroSize; }
 
   static std::shared_ptr<PdxSerializable> createDeserializable() {
     return std::make_shared<PortfolioPdx>();

Reply via email to