From d83bc5de931d106c58c7cc7353d6f7a464829dd4 Mon Sep 17 00:00:00 2001 From: Charl Wentzel Date: Wed, 29 Apr 2020 17:50:03 +0200 Subject: [PATCH] Important Update: - DataTreeCore (bug fix): - Copy only specified number of chars for Name in constructor - Copy only specified number of chars for value in SetValue --- DataTreeCore.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/DataTreeCore.cpp b/DataTreeCore.cpp index 49f221f..c2c1cb7 100644 --- a/DataTreeCore.cpp +++ b/DataTreeCore.cpp @@ -17,12 +17,12 @@ CDataMember::CDataMember( const char * pName, const int pLen ) { if (pName) { - Name = strdup( pName ); NameLen = (pLen == -1)? strlen( pName ) : pLen ; + Name = strndup( pName, NameLen ); } else { - Name = NULL; NameLen = 0; + Name = NULL; } Type = jtNull; @@ -41,12 +41,12 @@ CDataMember::CDataMember( const char * pName, const int pLen ) CDataMember::CDataMember( CDataMember * pParent, const char * pName, const int pLen ) { if (pName) { - Name = strdup( pName ); NameLen = (pLen == -1)? strlen( pName ) : pLen ; + Name = strndup( pName, NameLen ); } else { - Name = NULL; NameLen = 0; + Name = NULL; } Type = jtNull; @@ -372,8 +372,8 @@ bool CDataMember::SetValue( EJsonDataType pType, const char * pValue, int pLen // Set new primitive value if ((pType == jtString) || (pType == jtFloat) || (pType == jtInt) || (pType == jtBool)) { - Value = strdup( pValue ); Len = (pLen == -1)? strlen(pValue) : pLen; + Value = strndup( pValue, Len ); } return true; }