string internal set method has additional safeguard for bad data

This commit is contained in:
Noel Berry 2021-12-18 02:48:51 -08:00
parent 10c1c39419
commit 1ee2fbab3d
2 changed files with 19 additions and 7 deletions

View File

@ -199,6 +199,8 @@ namespace Blah
u8 wash;
u8 fill;
u8 pad;
Vertex() = default;
};
struct DrawBatch

View File

@ -471,12 +471,22 @@ void Str::set(const char* start, const char* end)
if (end == nullptr)
end = start + strlen(start);
// make sure it actually contains characters
int len = (int)(end - start);
if (len <= 0)
{
clear();
}
else
{
m_length = len;
// reserve
m_length = (int)(end - start);
reserve(m_length);
// copy the data over
char* ptr = data();
memcpy(ptr, start, m_length);
ptr[m_length] = '\0';
}
}