Page MenuHome

Fix T74510 wchar_t losing 16 bits of data on windows.
ClosedPublic

Authored by Ray Molenkamp (LazyDodo) on Dec 10 2020, 9:51 PM.

Details

Summary

This fixes the issues seen in T74510 the root cause of this issue is BLI_strncpy_wchar_from_utf8 assuming wchar_t being 32 bits for windows where it is not (UTF16 there), so it just clips off the upper 16 bits and asserts in case that ever happened. Which naturally came to bite us in the rear with some international users.

Given most of the code in BLI_strncpy_wchar_from_utf8 was a duplicate of BLI_str_utf8_as_utf32 this patch just calls the right functions for the right platforms.

Tests pass on windows, have not tested on linux/mac

Diff Detail

Repository
rB Blender
Branch
tmp_fix_T74510 (branched from master)
Build Status
Buildable 11679
Build 11679: arc lint + arc unit

Event Timeline

Ray Molenkamp (LazyDodo) requested review of this revision.Dec 10 2020, 9:51 PM
Ray Molenkamp (LazyDodo) created this revision.
Ray Molenkamp (LazyDodo) retitled this revision from Fix T74510 to Fix T74510 wchar_t losing 16 bits of data on windows. .Dec 10 2020, 9:52 PM
Ray Molenkamp (LazyDodo) edited the summary of this revision. (Show Details)

It would be great if this would make it into the 2.91.1 release :D
(We would voluntary test this build ;) )

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

This should be ifdef WIN32 otherwise this generates a warning on Linux as WIN32 is not defined.

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

GCC warns that the signedness of wchar_t (signed) is not the same as char32_t (unsigned).

like i said, i'm unable to test on linux/mac, i suppose a cast between wchar32_t and wchar_t would be permissible here?

A cast to (char32_t *) (without a w, see signature of BLI_str_utf8_as_utf32) should be fine, since this is a signed to unsigned cast. I haven't tested if it works properly on Linux yet, but will do tomorrow.

Seems to run well on Linux, but I have only done rudimentary tests.

Ray Molenkamp (LazyDodo) retitled this revision from Fix T74510 wchar_t losing 16 bits of data on windows. to Fix T74510 wchar_t losing 16 bits of data on windows..
  • Merge remote-tracking branch 'origin/master' into arcpatch-D9822
  • fix #if -> #ifdef
  • fix building on linux
This revision is now accepted and ready to land.Dec 16 2020, 6:47 PM
Ray Molenkamp (LazyDodo) marked 2 inline comments as done.Dec 17 2020, 2:37 AM

I forgot to land this, given we're already in bcon3 for 2.92 , should this land in 2.92 or master?

This revision was automatically updated to reflect the committed changes.