cosmopolitan/test/libc
Gabriel Ravier ba42248575
Fix larger than WCHAR_MAX differences in wcs{,n}cmp (#795)
The C standard states:

> Unless explicitly stated otherwise, the functions described in this
> subclause order two wide characters the same way as two integers of
> the underlying integer type designated by wchar_t.
>
> [...]
>
> The wcscmp function returns an integer greater than, equal to, or
> less than zero, accordingly as the wide string pointed to by s1 is
> greater than, equal to, or less than the wide string pointed to by
> s2.
>
> [...]
>
> The wcsncmp function returns an integer greater than, equal to, or
> less than zero, accordingly as the possibly null-terminated array
> pointed to by s1 is greater than, equal to, or less than the
> possibly null-terminated array pointed to by s2.
- C Standard, 7.31.4.4. Wide string comparison functions

Cosmopolitan fails to obey this in cases where the difference between
two wide characters is larger than WCHAR_MAX.

This means that, for example, the following program:

 #include <stdio.h>
 #include <wchar.h>
 #include <limits.h>

int main()
{
    wchar_t str1[] = { WCHAR_MIN, L'\0' };
    wchar_t str2[] = { WCHAR_MAX, L'\0' };
    printf("%d\n", wcscmp(str1, str2));
    printf("%d\n", wcsncmp(str1, str2, 2));
}

will print `1` twice, instead of the negative numbers mandated by the
standard (as WCHAR_MIN is less than WCHAR_MAX)

This patch fixes this, along with the associated Github issue,
https://github.com/jart/cosmopolitan/issues/783
2023-03-29 20:28:18 -04:00
..
bits Fold LIBC_BITS into LIBC_INTRIN 2022-08-11 12:13:18 -07:00
calls Avoid matching directories when searching PATH (#717) 2023-03-06 11:15:32 -05:00
dns Rename rand64() to _rand64() 2022-10-10 04:12:06 -07:00
fmt Fix memcpy(size=0) ubsan warning in vsnprintf() 2023-03-29 01:28:10 -07:00
intrin Make intrin_test go faster 2023-03-05 22:57:07 -08:00
log Add WSL to test fleet 2022-11-02 06:49:42 -07:00
mem Improve cancellations, randomness, and time 2022-11-05 23:45:32 -07:00
nexgen32e Rename rand64() to _rand64() 2022-10-10 04:12:06 -07:00
release Add *NSYNC to libc/isystem 2022-09-13 01:47:12 -07:00
runtime Remove problematic test 2023-02-05 16:50:04 -08:00
sock Update tests and CPU detection for Blink 2023-01-18 00:56:09 -08:00
stdio GetZipCdir: prevent integer underflow. posix_spawn_test.c: stop attempting to load zipos from /usr/bin/ape. (#758) 2023-03-05 14:29:38 -08:00
str Fix larger than WCHAR_MAX differences in wcs{,n}cmp (#795) 2023-03-29 20:28:18 -04:00
thread Make POSIX semaphores always process shared 2023-02-23 08:07:54 -08:00
time Make fixes and improvements 2022-10-19 07:19:19 -07:00
tinymath Pay off more technical debt 2022-09-12 23:36:56 -07:00
x Greatly expand system() shell code features 2022-10-11 21:30:31 -07:00
xed Pay off more technical debt 2022-09-12 23:36:56 -07:00
zipos Add fexecve() and map O_EXEC to O_PATH on Linux 2022-10-02 09:15:46 -07:00
test.mk Don't relocate file descriptor memory 2022-09-09 16:54:28 -07:00