https://bugs.kde.org/show_bug.cgi?id=397083

--- Comment #7 from Bruno Haible <br...@clisp.org> ---
(In reply to Paul Floyd from comment #5)
> Created attachment 158110 [details]

There's a small issue here: ISO C allows all possible wchar_t values to occur
in the arrays passed to wmemcmp(), and requires that the comparison be done
w.r.t. the order in the underlying integer type 'wchar_t'. For more on this
topic, please see https://www.openwall.com/lists/musl/2023/04/18/5 and
https://lists.gnu.org/archive/html/bug-gnulib/2023-04/msg00145.html .

Regarding your patch, this means that the line
         Int res = a0 - b0; \
should be replaced with something that does not assume that a0 and b0 are in
the range 0..INT_MAX. For example,
         Int res = (a0 > b0) - (a0 < b0);
(This expression on the right-hand side has the noce property that it does not
produce conditional jumps with GCC. See
https://lists.gnu.org/archive/html/bug-gnulib/2020-07/msg00109.html .)

Additionally, watch out: wchar_t is signed (i.e. equivalent to int32_t) on most
platforms. However it is unsigned (i.e. equivalent to uint32_t) on arm64
platforms (on glibc, musl libc, FreeBSD, but not on macOS).

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to