From 1ee2fbab3d41d6b7eb12dee3fc40236438ab36b9 Mon Sep 17 00:00:00 2001 From: Noel Berry Date: Sat, 18 Dec 2021 02:48:51 -0800 Subject: [PATCH] string internal set method has additional safeguard for bad data --- include/blah/graphics/batch.h | 2 ++ src/containers/str.cpp | 24 +++++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/blah/graphics/batch.h b/include/blah/graphics/batch.h index d475739..2003e95 100644 --- a/include/blah/graphics/batch.h +++ b/include/blah/graphics/batch.h @@ -199,6 +199,8 @@ namespace Blah u8 wash; u8 fill; u8 pad; + + Vertex() = default; }; struct DrawBatch diff --git a/src/containers/str.cpp b/src/containers/str.cpp index 8b30f6a..d4421a7 100644 --- a/src/containers/str.cpp +++ b/src/containers/str.cpp @@ -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'; + } } \ No newline at end of file