This is the mail archive of the 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]

[PATCH] Use correct signedness in wcsncmp.


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"

-"Fix signedness in wcscmp comparison"

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"

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?


2015-03-26  Stefan Liebler  <>

	* 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]