From 8adfb6fdb978748cfa38ba31a3addf34a5bfbc5c Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 28 Apr 2023 21:16:11 +0200 Subject: [PATCH] libluna: Leave String in a valid state when moved --- libluna/include/luna/String.h | 2 ++ libluna/src/String.cpp | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libluna/include/luna/String.h b/libluna/include/luna/String.h index 99aa7854..0bdf7395 100644 --- a/libluna/include/luna/String.h +++ b/libluna/include/luna/String.h @@ -91,5 +91,7 @@ class String usize m_length { 0 }; + void empty(); + static Result vformat(StringView fmt, va_list ap); }; diff --git a/libluna/src/String.cpp b/libluna/src/String.cpp index 8d5a6595..1a17bbbe 100644 --- a/libluna/src/String.cpp +++ b/libluna/src/String.cpp @@ -5,6 +5,11 @@ #include String::String() +{ + empty(); +} + +void String::empty() { m_inline = true; m_length = 0; @@ -20,7 +25,7 @@ String::String(String&& other) if (m_inline) memcpy(m_inline_storage, other.m_inline_storage, sizeof(m_inline_storage)); - other.m_string = nullptr; + other.empty(); } String& String::operator=(String&& other) @@ -36,7 +41,7 @@ String& String::operator=(String&& other) if (m_inline) memcpy(m_inline_storage, other.m_inline_storage, sizeof(m_inline_storage)); - other.m_string = nullptr; + other.empty(); return *this; }