This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
Hi,
the wcsncmp implementation does not behave the same as wcscmp
and wmemcmp due to using substraction instead of comparision:
wchar_t w0[] = { WCHAR_MIN, 0 };
wchar_t w1[] = { WCHAR_MAX, 0 };
wcscmp (w0, w1) = -1
wcsncmp (w0, w1, 2) = 1
wmemcmp (w0, w1, 2) = -1
This patch adjusts wcsncmp behavior in the same way,
as it was done for wcscmp and wmemcmp:
-"Use correct signedness in default implementations of wcscmp and wmemcmp"
(https://sourceware.org/git/?p=glibc.git;a=commit;h=1f1e194720177de3cbc2a84bc62d22e63cb23d4a)
-"Fix signedness in wcscmp comparison"
(https://sourceware.org/git/?p=glibc.git;a=commit;h=95584d3b3309ff4da4cc458254df383f5cff044b)
The testcase localedata/tests-mbwc/tst_wcsncmp.c expects the exact
character difference, therefore it is adjusted in the same way as
"wcscmp testsuite too strict"
(https://sourceware.org/ml/libc-alpha/2000-10/msg00001.html).
The testcase string/test-strncmp.c now supports testing wcsncmp if WIDE
is defined. The corresponding testcase wcsmbs/test-wcsncmp.c is added.
Tested on s390x and x86_64.
Ok to commit?
Bye
Stefan
---
2015-03-26 Stefan Liebler <stli@linux.vnet.ibm.com>
* wcsmbs/wcsncmp.c (wcsncmp): Compare as wchar_t, not wint_t.
Use signed comparision instead of substraction to avoid
overflow bug.
* localedata/tests-mbwc/tst_wcsncmp.c (tst_wcsncmp):
Take the sign of ret.
* localedata/tests-mbwc/dat_wcsncmp.c (tst_wcsncmp_loc):
DonÂt expect precise return values. Only the sign matters.
* wcsmbs/Makefile (strop-tests): Add wcsncmp.
* wcsmbs/test-wcsncmp.c: New File.
* string/test-strncmp.c: Add wcsncmp support.
Attachment:
wcsncmp_26032015
Description: Text document
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |