D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2783 - Truncation of long string by std.stdio.write
Summary: Truncation of long string by std.stdio.write
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: Andrei Alexandrescu
URL: http://www.britseyeview.com/middle.txt
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-02 05:01 UTC by Steve Teale
Modified: 2015-06-09 01:18 UTC (History)
1 user (show)

See Also:


Attachments
The file used in my description of the issue (86.68 KB, text/plain)
2009-04-02 05:03 UTC, Steve Teale
Details

Note You need to log in before you can comment on or make changes to this issue.
Description Steve Teale 2009-04-02 05:01:18 UTC
Walter,

The file middle.txt at the URL above has lines numbered up to 555. If I read it into a string and std.stdio.write the string to the console, the output is truncated at line 261.

import std.file;
import std.stdio;
import std.c.stdio;

void main()
{
   string s2 = cast(immutable(char[])) std.file.read("middle.txt");
   std.stdio.write(s2);
   printf("%s", (s2 ~ "\x00").ptr);
}

It isn't std.file.read, as I got similar behavior when the string was output to the console from the program that generated middle.txt - then it was at line 221.

I checked the string for embedded zeroes and 0x1a when it was doing the fail at 221, but it seemed to be OK.

printf works as expected.

I'm sorry I can't come up with anything more compact than this, and I'm probably missing something stupid.

Steve
Comment 1 Steve Teale 2009-04-02 05:03:48 UTC
Created attachment 310 [details]
The file used in my description of the issue
Comment 2 anonymous4 2009-04-02 07:40:35 UTC
format.d
1623: short precision = short.max - 1;
2010: auto s = obj[0 .. f.precision < $ ? f.precision : $];
2016: w.write(s);

try std.stdio.write("%s",s2);
Comment 3 Andrei Alexandrescu 2009-04-02 08:23:53 UTC
I've fixed the problem, will be part of the next release.

Andrei
Comment 4 Andrei Alexandrescu 2010-09-26 14:25:37 UTC
Fixed a while ago.