Issue 5001 - std.stream read(char[]) and write(char[]) not 64bit safe
Summary: std.stream read(char[]) and write(char[]) not 64bit safe
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All Linux
: P2 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-06 09:07 UTC by Daniel Gibson
Modified: 2015-11-03 16:08 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Daniel Gibson 2010-10-06 09:07:08 UTC
As mentioned in the NG[1], OutputStreams write(char[]) and write(wchar[]), that write "a string, together with its length", are not 64bit safe, because they write first the length as a size_t (which is uint on x86 und ulong on amd64 afaik).
This means that you can't use write(char[]) to write into a file on a x86 system (or a 32bit executable on an amd64 system) and later read that file on an amd64 system. Also consider SocketStream.. you can't use SocketStream.write(char[]) to communicate between a x86 and an amd64 box (when an 64bit executable is used an the latter).
This could easily be fixed by using uint or ulong instead of size_t on all platforms. (uint is probably ok, Java even uses short in a similar method (java.io.DataOutput.writeUTF() - never use this, it's no real UTF-8)). 

Unfortunately the libphobos of GDC (that already supports 64bit targets) has been using size_t for ages, so in D1 it should *maybe* stay like that to avoid breaking compatibility.
On the other hand, probably no GDC user who thinks at least a bit cross-platform uses write(char[]) anyway, so it might suffice to use uint so it's compatible with existing 32bit binaries from DMD.

But at least for D2/phobos2 write( (w)char[] ) should either use uint or ulong, but not size_t.

Of course read( (w)char[] ) needs to be updated as well.


[1] http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=118413
Comment 1 Robert Schadek 2015-11-03 16:08:28 UTC
std.stream is deprecated and will be removed in 2016