From 4dc060e0b36d2f2bfca7feb8f8b5cad13af313da Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 11 Feb 2024 17:09:37 +0100 Subject: [PATCH] libluna: Fix String::from_string_view construction for inline strings Before, this method failed to add a null terminator if the source string did not have one, which was possible. --- libluna/src/String.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libluna/src/String.cpp b/libluna/src/String.cpp index e606e77a..f8f00464 100644 --- a/libluna/src/String.cpp +++ b/libluna/src/String.cpp @@ -155,7 +155,8 @@ Result String::from_string_view(StringView str) String result; result.m_inline = true; result.m_length = str.length(); - strncpy(result.m_inline_storage, str.chars(), sizeof(m_inline_storage)); + memset(result.m_inline_storage, 0, sizeof(result.m_inline_storage)); + memcpy(result.m_inline_storage, str.chars(), str.length()); return result; }