libstdc++/5286: std::wofstream writing wchar_t* strings

kingleo@gmx.at kingleo@gmx.at
Sun Jan 6 00:16:00 GMT 2002


>Number:         5286
>Category:       libstdc++
>Synopsis:       std::wofstream writing wchar_t* strings
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jan 06 00:16:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Martin Oberzalek
>Release:        gcc version 3.0.3
>Organization:
>Environment:
i686 Athlon Debian/GNU/Linux/unstable
Linux 2.4.13-pre6
>Description:
std::wofstream::write( wchar_t*, n );

This function does not writes n elements of the wchar_t* string into the file. 
It writes n bytes of the wchar_t* string into the file.
>How-To-Repeat:
Simple compile the code with g++-3.0.3 and execute the program and then have a look at the created file "foobar".
On my system od says this:
$ od -c foobar
0000000   S  \0  \0  \0   h  \0  \0  \0   i  \0  \0
0000013

The string "Shithappens" won't be written completely as an UCS-4LE (on i386) string to the file. Only 11 bytes, thats the number of letters of the word "Shithappens", will be written to the file.
>Fix:
Workaround:
 wstring s = L"Shithappens";
 out.write( s.c_str(), s.size() * sizeof( wchar_t ) );

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/x-c++src; name="wfstream.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="wfstream.cpp"

I2luY2x1ZGUgPGZzdHJlYW0+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHN0cmluZz4K
CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpCnsKICB3b2ZzdHJlYW0gb3V0KCAiZm9v
YmFyIiwgc3RkOjppb3NfYmFzZTo6b3V0IHwgc3RkOjppb3NfYmFzZTo6dHJ1bmMgKTsKCiAgaWYo
IG91dC5nb29kKCkgKQogICAgewogICAgIG91dCA8PCBMIlNoaXRoYXBwZW5zIjsKCiAgICAgLy8g
V29ya2Fyb3VuZDoKICAgICAvLyAgICAgIHdzdHJpbmcgcyA9IEwiU2hpdGhhcHBlbnMiOwogICAg
IC8vICAgICAgb3V0LndyaXRlKCBzLmNfc3RyKCksIHMuc2l6ZSgpICogc2l6ZW9mKCB3Y2hhcl90
ICkgKTsKICAgIH0KICBlbHNlCiAgICB3Y291dCA8PCAiY2Fubm90IG9wZW4gZmlsZSIgPDwgZW5k
bDsKICAgIAogIHdjb3V0IDw8ICJkb25lIiA8PCBlbmRsOwoKICByZXR1cm4gMDsKfQo=



More information about the Gcc-bugs mailing list