From 164a5e587eaf51b23b8308ea4900f59338bdb6f5 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Fri, 5 Jul 2024 13:46:07 +0200 Subject: [PATCH 1/2] Fix utf8_to_wstring given zero bytes. --- core/sys/windows/util.odin | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/sys/windows/util.odin b/core/sys/windows/util.odin index c68d58de0..348eb9e5f 100644 --- a/core/sys/windows/util.odin +++ b/core/sys/windows/util.odin @@ -53,8 +53,11 @@ utf8_to_utf16 :: proc(s: string, allocator := context.temp_allocator) -> []u16 { return text[:n] } utf8_to_wstring :: proc(s: string, allocator := context.temp_allocator) -> wstring { - if res := utf8_to_utf16(s, allocator); res != nil { + if res := utf8_to_utf16(s, allocator); len(res) > 0 { return &res[0] + } else { + delete(res, allocator) + return nil } return nil } From 9ecc33570b13e2685b494b9fc618cf6c6c7c5f2d Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Fri, 5 Jul 2024 13:51:38 +0200 Subject: [PATCH 2/2] Improve fix. --- core/sys/windows/util.odin | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/core/sys/windows/util.odin b/core/sys/windows/util.odin index 348eb9e5f..be0d8c02b 100644 --- a/core/sys/windows/util.odin +++ b/core/sys/windows/util.odin @@ -54,10 +54,7 @@ utf8_to_utf16 :: proc(s: string, allocator := context.temp_allocator) -> []u16 { } utf8_to_wstring :: proc(s: string, allocator := context.temp_allocator) -> wstring { if res := utf8_to_utf16(s, allocator); len(res) > 0 { - return &res[0] - } else { - delete(res, allocator) - return nil + return raw_data(res) } return nil }