From 80ce1b7d850d264f5d8538724aa2b43e8e4a5c09 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 18 Oct 2022 10:28:17 +0100 Subject: [PATCH] Allow for `N = -1` in `wstring_to_utf8` --- core/sys/windows/util.odin | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/sys/windows/util.odin b/core/sys/windows/util.odin index 36383a2c7..298588cb6 100644 --- a/core/sys/windows/util.odin +++ b/core/sys/windows/util.odin @@ -62,19 +62,19 @@ utf8_to_wstring :: proc(s: string, allocator := context.temp_allocator) -> wstri wstring_to_utf8 :: proc(s: wstring, N: int, allocator := context.temp_allocator) -> (res: string, err: runtime.Allocator_Error) { context.allocator = allocator - if N <= 0 { + if N == 0 { return } - n := WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, s, i32(N), nil, 0, nil, nil) + n := WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, s, i32(N) if N > 0 else -1, nil, 0, nil, nil) if n == 0 { return } - // If N == -1 the call to WideCharToMultiByte assume the wide string is null terminated + // If N < 0 the call to WideCharToMultiByte assume the wide string is null terminated // and will scan it to find the first null terminated character. The resulting string will // also be null terminated. - // If N != -1 it assumes the wide string is not null terminated and the resulting string + // If N > 0 it assumes the wide string is not null terminated and the resulting string // will not be null terminated. text := make([]byte, n) or_return