From 58466a6f3b715baf060467dfd9cbe36db55f108c Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 12 Jun 2020 15:01:43 +0100 Subject: [PATCH] Add extra NUL termination check for string length in win32 general string convertors --- core/sys/win32/general.odin | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/sys/win32/general.odin b/core/sys/win32/general.odin index b0424b78d..2ed584fd7 100644 --- a/core/sys/win32/general.odin +++ b/core/sys/win32/general.odin @@ -791,8 +791,10 @@ utf8_to_utf16 :: proc(s: string, allocator := context.temp_allocator) -> []u16 { } text[n] = 0; - - return text[:len(text)-1]; + for n >= 0 && text[n] == 0 { + n -= 1; + } + return text[:n]; } utf8_to_wstring :: proc(s: string, allocator := context.temp_allocator) -> Wstring { if res := utf8_to_utf16(s, allocator); res != nil { @@ -821,7 +823,10 @@ utf16_to_utf8 :: proc(s: []u16, allocator := context.temp_allocator) -> string { text[n] = 0; - return string(text[:len(text)-1]); + for n >= 0 && text[n] == 0 { + n -= 1; + } + return string(text[:n]); }