string internal set method has additional safeguard for bad data

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

No files matched your search

+2
View File
@@ -199,6 +199,8 @@ namespace Blah
u8 wash;
u8 fill;
u8 pad;
Vertex() = default;
};
struct DrawBatch
+17 -7
View File
@@ -471,12 +471,22 @@ void Str::set(const char* start, const char* end)
if (end == nullptr)
end = start + strlen(start);
// reserve
m_length = (int)(end - start);
reserve(m_length);
// make sure it actually contains characters
int len = (int)(end - start);
if (len <= 0)
{
clear();
}
else
{
m_length = len;
// reserve
reserve(m_length);
// copy the data over
char* ptr = data();
memcpy(ptr, start, m_length);
ptr[m_length] = '\0';
// copy the data over
char* ptr = data();
memcpy(ptr, start, m_length);
ptr[m_length] = '\0';
}
}