diff --git a/kernel/src/memory/MemoryManager.cpp b/kernel/src/memory/MemoryManager.cpp index 26b75e63..4ee6e119 100644 --- a/kernel/src/memory/MemoryManager.cpp +++ b/kernel/src/memory/MemoryManager.cpp @@ -431,7 +431,7 @@ namespace MemoryManager TRY(result.try_append(0)); // null terminator - return String::from_cstring(result.data()); + return String { result.release_data() }; } bool validate_access(const void* mem, usize size, int flags) diff --git a/libluna/src/Base64.cpp b/libluna/src/Base64.cpp index 25cdaf8e..203bccd6 100644 --- a/libluna/src/Base64.cpp +++ b/libluna/src/Base64.cpp @@ -152,6 +152,6 @@ namespace Base64 u8 nul_byte = '\0'; TRY(buf.append_data(&nul_byte, 1)); - return String::from_cstring((char*)buf.data()); + return String { (char*)buf.release_data() }; } } diff --git a/libluna/src/Buffer.cpp b/libluna/src/Buffer.cpp index b08bf35b..960e848d 100644 --- a/libluna/src/Buffer.cpp +++ b/libluna/src/Buffer.cpp @@ -52,3 +52,10 @@ Result Buffer::append_data(const u8* data, usize size) return {}; } + +u8* Buffer::release_data() +{ + u8* data = m_data; + m_data = nullptr; + return data; +} diff --git a/libluna/src/String.cpp b/libluna/src/String.cpp index 317e0578..a2466f66 100644 --- a/libluna/src/String.cpp +++ b/libluna/src/String.cpp @@ -140,7 +140,7 @@ Result String::vformat(StringView fmt, va_list ap) TRY(buf.try_append(0)); - return from_cstring(buf.data()); + return String { buf.release_data() }; } Result String::from_cstring(const char* str) diff --git a/libluna/src/StringBuilder.cpp b/libluna/src/StringBuilder.cpp index 8ee9065c..f85aa920 100644 --- a/libluna/src/StringBuilder.cpp +++ b/libluna/src/StringBuilder.cpp @@ -61,5 +61,5 @@ Result StringBuilder::string() char nul = '\0'; TRY(m_data.append_data((u8*)&nul, 1)); - return String::from_cstring((const char*)m_data.data()); + return String { (char*)m_data.release_data() }; } diff --git a/libos/src/File.cpp b/libos/src/File.cpp index 9087dc28..3e0f2f46 100644 --- a/libos/src/File.cpp +++ b/libos/src/File.cpp @@ -143,7 +143,7 @@ namespace os TRY(data.try_append('\0')); - return String::from_cstring(data.data()); + return String { data.release_data() }; } Result File::read_all_as_string()