Compare commits

...

2 Commits

Author SHA1 Message Date
4dc060e0b3
libluna: Fix String::from_string_view construction for inline strings
All checks were successful
Build and test / build (push) Successful in 1m41s
Before, this method failed to add a null terminator if the source string did not have one, which was possible.
2024-02-11 17:09:37 +01:00
644614cdd8
libluna: Fix memmove when dest > src
Really? A crucial component of the libc was broken? No wonder some ports did not work very well...
2024-02-11 17:08:36 +01:00
2 changed files with 3 additions and 2 deletions

View File

@ -51,7 +51,7 @@ extern "C"
{ {
if (dest == src) return dest; if (dest == src) return dest;
if (dest > src) if (dest > src)
for (long i = (long)n - 1; i >= 0; i++) { *((u8*)dest + i) = *((const u8*)src + i); } for (long i = (long)n - 1; i >= 0; i--) { *((u8*)dest + i) = *((const u8*)src + i); }
else else
for (long i = 0; i < (long)n; i++) { *((u8*)dest + i) = *((const u8*)src + i); } for (long i = 0; i < (long)n; i++) { *((u8*)dest + i) = *((const u8*)src + i); }
return dest; return dest;

View File

@ -155,7 +155,8 @@ Result<String> String::from_string_view(StringView str)
String result; String result;
result.m_inline = true; result.m_inline = true;
result.m_length = str.length(); 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; return result;
} }