mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-10-27 19:34:33 +00:00
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
|
||
|---|---|---|
| .. | ||
| a64l_test.c | ||
| blake2_test.c | ||
| blake2b256_tests.txt | ||
| bsr_test.c | ||
| bzero_test.c | ||
| classifypath_test.c | ||
| crc32c_test.c | ||
| crc32z_test.c | ||
| hexpcpy_test.c | ||
| highwayhash64_test.c | ||
| isutf8_test.c | ||
| longsort_test.c | ||
| memcasecmp_test.c | ||
| memccpy_test.c | ||
| memcpy_test.c | ||
| memfrob_test.c | ||
| memmem_test.c | ||
| memmove_test.c | ||
| memrchr16_test.c | ||
| memrchr_test.c | ||
| regex_test.c | ||
| setlocale_test.c | ||
| str_test.c | ||
| strcasecmp_test.c | ||
| strcasestr_test.c | ||
| strcat_test.c | ||
| strchr_test.c | ||
| strclen_test.c | ||
| strcmp_test.c | ||
| strcpy_test.c | ||
| strlcpy_test.c | ||
| strnlen_test.c | ||
| strnwidth_test.c | ||
| strpbrk_test.c | ||
| strrchr_test.c | ||
| strstr_test.c | ||
| strtok_r_test.c | ||
| strtolower_test.c | ||
| test.mk | ||
| towupper_test.c | ||
| tpenc_test.c | ||
| tprecode8to16_test.c | ||
| tprecode16to8_test.c | ||
| wcsrchr_test.c | ||
| wcwidth_test.c | ||
| wmemrchr_test.c | ||