libstdc++/9817: collate::compare doesn't handle nul characters.

peturr02@ru.is peturr02@ru.is
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
>Closed-Date:
>Last-Modified:
>Originator:     peturr02@ru.is
>Release:        gcc-3.2.1
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
collate::compare stops when it finds a nul character in the string, thus the strings "a\0a" and "a\0b" compare equal.
>How-To-Repeat:
See attachment.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="collatebug.cc"
Content-Disposition: inline; filename="collatebug.cc"

#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(coll.compare(str1, str1 + 3, str2, str2 + 3) < 0);
	return 0;
}



More information about the Gcc-bugs mailing list