Unexpected Crash

default0 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Apr 7 13:42:17 PDT 2016


Consider the following program:

import std.stdio;

void main(string[] args) {
     int a, b, c;
     while(true) {
         readf("%d,%d,%d", &a, &b, &c);
         writeln(a, b, c);
     }
}

If I enter "5,5,5" on the commandline, hit enter, then enter 
"5,5,5" a second time, hit enter again, the second time it 
crashes. Why? What am I getting wrong here?

The error I am getting is the following:
std.conv.ConvException@/usr/include/dmd/phobos/std/conv.d(2002): 
Unexpected '5' when converting from type LockingTextReader to 
type int
----------------
/usr/include/dmd/phobos/std/conv.d:58 int std.conv.parse!(int, 
std.stdio.LockingTextReader).parse(ref 
std.stdio.LockingTextReader) [0x440072]
/usr/include/dmd/phobos/std/conv.d:2226 int std.conv.parse!(int, 
std.stdio.LockingTextReader).parse(ref 
std.stdio.LockingTextReader, uint) [0x43fd63]
/usr/include/dmd/phobos/std/format.d:4383 int 
std.format.unformatValue!(int, std.stdio.LockingTextReader, 
char).unformatValue(ref std.stdio.LockingTextReader, ref 
std.format.FormatSpec!(char).FormatSpec) [0x43f529]
/usr/include/dmd/phobos/std/format.d:631 uint 
std.format.formattedRead!(std.stdio.LockingTextReader, char, 
int*, int*, int*).formattedRead(ref std.stdio.LockingTextReader, 
const(char)[], int*, int*, int*) [0x43a452]
/usr/include/dmd/phobos/std/stdio.d:1661 uint 
std.stdio.File.readf!(int*, int*, int*).readf(const(char[]), 
int*, int*, int*) [0x43a391]
/usr/include/dmd/phobos/std/stdio.d:3331 uint 
std.stdio.readf!(int*, int*, int*).readf(const(char[]), int*, 
int*, int*) [0x43a2a7]
source/app.d:47 _Dmain [0x43a253]
??:? 
_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv 
[0x44852a]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) [0x448468]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).runAll() [0x4484e6]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) [0x448468]
??:? _d_run_main [0x4483c5]
??:? main [0x4445f7]
??:? __libc_start_main [0xdddd2a3f]


More information about the Digitalmars-d-learn mailing list