http://d.puremagic.com/issues/show_bug.cgi?id=10344
Summary: Exiting _Dmain should flush all FILE*s and return
nonzero on failure
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: [email protected]
ReportedBy: [email protected]
--- Comment #0 from Andrei Alexandrescu <[email protected]> 2013-06-12 09:33:32
PDT ---
Consider:
// file test.d
import std.stdio;
void main()
{
writeln("test");
}
This program may be run with a file that is not writable like this:
./test 1</dev/null
Although writeln() is checked, the program appears to succeed (returning 0 to
the OS) because of buffering: (a) /dev/null is not line-buffered, and (b)
flushing files upon exiting the program is unchecked.
To wit, this will indeed work correctly in all scenarios:
// file test.d
import std.stdio;
int main()
{
writeln("test");
return fflush(null) != 0;
}
We should add the call to fflush to main() and return nonzero IF AND ONLY IF:
(a) fflush(null) fails, and (b) the program would have otherwise returned 0.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------