From 7809185daad445d45456475680263626baa04992 Mon Sep 17 00:00:00 2001 From: Doyle Thai Date: Sat, 6 Jan 2018 16:53:53 +1100 Subject: [PATCH] Fix string append crash on 0 len --- dqn.h | 4 ++++ dqn_unit_test.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dqn.h b/dqn.h index f367c1d..ed94b33 100644 --- a/dqn.h +++ b/dqn.h @@ -5456,6 +5456,10 @@ bool DqnString::Expand(const i32 newMax) DQN_FILE_SCOPE bool DqnStringInternal_Append(DqnString *const str, char const *const cstr, i32 const bytesToCopy) { + if (bytesToCopy <= 0) + { + return true; + } // Check and reserve space if needed i32 totalLen = str->len + bytesToCopy; diff --git a/dqn_unit_test.cpp b/dqn_unit_test.cpp index cc0831c..127b2fa 100644 --- a/dqn_unit_test.cpp +++ b/dqn_unit_test.cpp @@ -605,7 +605,7 @@ void DqnString_Test() char *literal = "this is a literal string"; DqnString str = {}; DQN_ASSERT(str.InitLiteralNoAlloc(literal)); - DQN_ASSERT(str.Append(", hello again") == false); + DQN_ASSERT(str.Append(", hello again") == false); str.Free(); LogSuccess("DqnString(): Try init literl no alloc, no further expansion"); }