www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript
electronics



D.gnu - Bug in std.stdio.readln()

The following code causes a segfault for me on both x86 and amd64 systems.
This happens with both the gentoo 'emerge dev-lang/gcc' with USE=d and with
the gdc 0.24 binary distribution:

======================================================================
module readline;

import std.stdio;

void main ()
{
     while (1) {
	char[] buf = readln ();
	if (buf is null)
	    break;
	writef ("%s", buf);
     }
}
======================================================================

Upon EOF, there is a segfault inside of a string dup inside of readln:

   uint std.stdio.readln(struct std.c.stdio._iobuf*, inout char[])

#0  0xb7ed6a2c in memcpy () from /lib/libc.so.6
#1  0x0805992e in _adDupT ()
#2  0x080546e5 in _D3std5stdio6readlnFPS3std1c5stdio6_iobufKAaZk ()
#3  0x0805476a in _D3std5stdio6readlnFPS3std1c5stdio6_iobufZAa ()
#4  0x0804a076 in _Dmain ()
#5  0x08061018 in _D9dgccmain211_d_run_mainUiPPaPUAAaZiZi2goMFZv ()
#6  0x080610ca in _d_run_main ()
#7  0x0805d49b in main ()

I can try to build phobos with debugging symbols if other are unable to
reproduce this problem.

I will work around this by reading the file in characters.

Thanks,
David Brown
Sep 30 2007