diff --git a/src/xenia/base/string_buffer.cc b/src/xenia/base/string_buffer.cc index 5bc3bad0a..90d386f23 100644 --- a/src/xenia/base/string_buffer.cc +++ b/src/xenia/base/string_buffer.cc @@ -12,13 +12,15 @@ #include #include +#include "xenia/base/assert.h" #include "xenia/base/math.h" namespace xe { StringBuffer::StringBuffer(size_t initial_capacity) { buffer_capacity_ = std::max(initial_capacity, static_cast(16 * 1024)); - buffer_ = reinterpret_cast(malloc(buffer_capacity_)); + buffer_ = reinterpret_cast(std::malloc(buffer_capacity_)); + assert_not_null(buffer_); buffer_[0] = 0; } @@ -40,7 +42,9 @@ void StringBuffer::Grow(size_t additional_length) { size_t new_capacity = std::max(xe::round_up(buffer_offset_ + additional_length, 16 * 1024), old_capacity * 2); - buffer_ = reinterpret_cast(realloc(buffer_, new_capacity)); + auto new_buffer = std::realloc(buffer_, new_capacity); + assert_not_null(new_buffer); + buffer_ = reinterpret_cast(new_buffer); buffer_capacity_ = new_capacity; } @@ -57,7 +61,11 @@ void StringBuffer::Append(const std::string_view value) { } void StringBuffer::AppendVarargs(const char* format, va_list args) { - int length = vsnprintf(nullptr, 0, format, args); + int result = vsnprintf(nullptr, 0, format, args); + if (result <= 0) { + return; + } + auto length = static_cast(result); Grow(length + 1); vsnprintf(buffer_ + buffer_offset_, buffer_capacity_, format, args); buffer_offset_ += length;