libstdc++/9817: collate::compare doesn't handle nul characters.
Sun Feb 23 12:06:00 GMT 2003

>Number:         9817
>Category:       libstdc++
>Synopsis:       collate::compare doesn't handle nul characters.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Feb 23 12:06:00 UTC 2003
>Release:        gcc-3.2.1
Red Hat Linux 8.0
collate::compare stops when it finds a nul character in the string, thus the strings "a\0a" and "a\0b" compare equal.
See attachment.

Content-Type: text/plain; name=""
Content-Disposition: inline; filename=""

#include <locale>

#undef NDEBUG
#include <cassert>

int main()
	using namespace std;
	typedef collate<char> collate_type;

	locale loc = locale::classic();
	const collate_type& coll = use_facet<collate_type>(loc);

	char str1[] = { 'a', '\0', 'a' };
	char str2[] = { 'a', '\0', 'b' };

	assert(, str1 + 3, str2, str2 + 3) < 0);
	return 0;

More information about the Gcc-bugs mailing list