public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* libstdc++/9246: Bad handling of nul characters in codecvt<wchar_t, char, mbstate_t>
@ 2003-01-09 15:56 peturr02
0 siblings, 0 replies; only message in thread
From: peturr02 @ 2003-01-09 15:56 UTC (permalink / raw)
To: gcc-gnats
>Number: 9246
>Category: libstdc++
>Synopsis: Bad handling of nul characters in codecvt<wchar_t, char, mbstate_t>
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Jan 09 07:56:03 PST 2003
>Closed-Date:
>Last-Modified:
>Originator: peturr02@ru.is
>Release: gcc-3.2.1
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
If the input buffer for codecvt<wchar_t, char, mbstate_t>::do_out contains nul characters, from_next is not set properly and the function may return partial even though there is plenty of space left in the output buffer.
>How-To-Repeat:
See attachment.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="nulbug.cc"
Content-Disposition: inline; filename="nulbug.cc"
#include <locale>
#include <cwchar>
#include <cassert>
#include <cstring>
void test01()
{
using namespace std;
typedef codecvt<wchar_t, char, mbstate_t> w_codecvt;
const wchar_t wnul[] = { L'\0' };
const wchar_t* from_next;
char buffer[1024];
char* to_next;
locale loc;
const w_codecvt& cvt = use_facet<w_codecvt>(loc);
mbstate_t state;
memset(&state, 0, sizeof(state));
codecvt_base::result res =
cvt.out(state, wnul, wnul + 1, from_next, buffer,
buffer + sizeof(buffer), to_next);
assert(res != codecvt_base::noconv);
if (res == codecvt_base::ok)
{
assert(from_next == wnul + 1);
assert(to_next > buffer);
assert(to_next <= buffer + sizeof(buffer));
}
else if (res == codecvt_base::partial)
{
assert(to_next == buffer);
assert(from_next == wnul);
}
else if (res == codecvt_base::error)
{
assert(to_next == buffer);
assert(from_next == wnul);
}
}
void test02()
{
using namespace std;
typedef codecvt<wchar_t, char, mbstate_t> w_codecvt;
const wchar_t wstr[] = { L'a', L'\0' };
const wchar_t* from_next;
char buffer[1024];
char* to_next;
locale loc;
const w_codecvt& cvt = use_facet<w_codecvt>(loc);
mbstate_t state;
memset(&state, 0, sizeof(state));
codecvt_base::result res =
cvt.out(state, wstr, wstr + 2, from_next, buffer,
buffer + sizeof(buffer), to_next);
assert(res != codecvt_base::noconv);
if (res == codecvt_base::ok)
{
assert(from_next == wstr + 2);
assert(to_next > buffer);
assert(to_next <= buffer + sizeof(buffer));
}
else if (res == codecvt_base::partial)
{
assert(to_next > buffer);
assert(to_next <= buffer + sizeof(buffer));
assert(from_next >= wstr);
assert(from_next < wstr + 2);
}
else if (res == codecvt_base::error)
{
assert(to_next > buffer);
assert(to_next <= buffer + sizeof(buffer));
assert(from_next >= wstr);
assert(from_next < wstr + 2);
}
}
int main()
{
//test01();
test02();
return 0;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2003-01-09 15:56 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-09 15:56 libstdc++/9246: Bad handling of nul characters in codecvt<wchar_t, char, mbstate_t> peturr02
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).