[Bf-blender-cvs] [2f7258d618a] master: Fix BLI_strncpy_wchar_from_utf8 result on Windows

Campbell Barton noreply at git.blender.org
Sun Aug 29 04:11:37 CEST 2021


Commit: 2f7258d618a2a38fc982a9e0d0d7dd3cbc95ab3a
Author: Campbell Barton
Date:   Sun Aug 29 12:06:15 2021 +1000
Branches: master
https://developer.blender.org/rB2f7258d618a2a38fc982a9e0d0d7dd3cbc95ab3a

Fix BLI_strncpy_wchar_from_utf8 result on Windows

This function was documented to return the length but returned an
error value for WIN32. While this doesn't cause any bugs at the moment,
it could cause problems in the future.

Oversight in 5496d8cd361385268316f91afa150e69b5345ab0.

===================================================================

M	source/blender/blenlib/intern/string_utf8.c

===================================================================

diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c
index 3a5e2713b76..b9ea538ff24 100644
--- a/source/blender/blenlib/intern/string_utf8.c
+++ b/source/blender/blenlib/intern/string_utf8.c
@@ -378,7 +378,9 @@ size_t BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst_w,
                                    const size_t maxncpy)
 {
 #ifdef WIN32
-  return conv_utf_8_to_16(src_c, dst_w, maxncpy);
+  conv_utf_8_to_16(src_c, dst_w, maxncpy);
+  /* NOTE: it would be more efficient to calculate the length as part of #conv_utf_8_to_16. */
+  return wcslen(dst_w);
 #else
   return BLI_str_utf8_as_utf32((char32_t *)dst_w, src_c, maxncpy);
 #endif



More information about the Bf-blender-cvs mailing list