Fix string append crash on 0 len

This commit is contained in:
Doyle Thai 2018-01-06 16:53:53 +11:00
parent fd00b9071c
commit 7809185daa
2 changed files with 5 additions and 1 deletions

4
dqn.h
View File

@ -5456,6 +5456,10 @@ bool DqnString::Expand(const i32 newMax)
DQN_FILE_SCOPE bool DqnStringInternal_Append(DqnString *const str, char const *const cstr, DQN_FILE_SCOPE bool DqnStringInternal_Append(DqnString *const str, char const *const cstr,
i32 const bytesToCopy) i32 const bytesToCopy)
{ {
if (bytesToCopy <= 0)
{
return true;
}
// Check and reserve space if needed // Check and reserve space if needed
i32 totalLen = str->len + bytesToCopy; i32 totalLen = str->len + bytesToCopy;

View File

@ -605,7 +605,7 @@ void DqnString_Test()
char *literal = "this is a literal string"; char *literal = "this is a literal string";
DqnString str = {}; DqnString str = {};
DQN_ASSERT(str.InitLiteralNoAlloc(literal)); DQN_ASSERT(str.InitLiteralNoAlloc(literal));
DQN_ASSERT(str.Append(", hello again") == false); DQN_ASSERT(str.Append(", hello again") == false);
str.Free(); str.Free();
LogSuccess("DqnString(): Try init literl no alloc, no further expansion"); LogSuccess("DqnString(): Try init literl no alloc, no further expansion");
} }