View mode: basic / threaded / horizontal-split · Log in · Help
August 20, 2003
Bug in Outbuffer?
I copied the code from outbuffer.d to a new file. It looks like this:
import outbuffer;
int main(){
    OutBuffer buf = new OutBuffer();

    //printf("buf = %p\n", buf);
    //printf("buf.offset = %x\n", buf.offset);
    assert(buf.offset == 0);
    buf.write("hello");
    buf.write(cast(byte)0x20);
    buf.write("world");
    buf.printf(" %d", 6);
    // printf("buf = '%.*s'\n", buf.toString());
    return 0;
}

If I run this code I code crash with this backtrace:
(gdb) run
Starting program: /home/frido/Arbeit/LM/D/src/bug_1
(no debugging symbols found)...[New Thread 16384 (LWP 5652)]
(no debugging symbols found)...
(no debugging symbols found)...(no debugging symbols found)...
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 16384 (LWP 5652)]
0x08049c3b in _D9outbuffer9OutBuffer6spreadFkkZv ()
(gdb) backtrace
#0  0x08049c3b in _D9outbuffer9OutBuffer6spreadFkkZv ()
#1  0x08048ffb in _Dmain ()
#2  0x080494c4 in main ()
#3  0x400abd04 in __libc_start_main () from /lib/libc.so.6


I do not think that this should happen.

I'm running DMD 0.69 on a Debian/unstable box Libc version 2.3.x


Another point. I wrote about a generic way for printing objects. Now it 
seems Outbuffer is the answer, unfortunatly there's not function for 
printing an Object. I wonder if this patch would work:
    void write(Object o){
        reserve(o.toString().size);
        write(o.toString());
}

Regards
Friedrich
August 22, 2003
Re: Bug in Outbuffer?
Try deleting lines of code from it until the problem goes away, that way at
least it's down to which line is the problem.
August 25, 2003
Re: Bug in Outbuffer?
Walter wrote:
> Try deleting lines of code from it until the problem goes away, that way at
> least it's down to which line is the problem.
> 
> 
The bugs seems to be with printf:
This works:
import outbuffer;
int main(){
    OutBuffer buf = new OutBuffer();

    //printf("buf = %p\n", buf);
    //printf("buf.offset = %x\n", buf.offset);
    assert(buf.offset == 0);
    buf.write("hello");
    buf.write(cast(byte)0x20);
    //buf.write("world");
    // buf.printf(" %d", 6);
    printf("buf = '%.*s'\n", buf.toString());
    return 0;
}

this crashes:
import outbuffer;
int main(){
    OutBuffer buf = new OutBuffer();

    //printf("buf = %p\n", buf);
    //printf("buf.offset = %x\n", buf.offset);
    assert(buf.offset == 0);
    buf.write("hello");
    buf.write(cast(byte)0x20);
    //buf.write("world");
    buf.printf(" %d", 6);
    printf("buf = '%.*s'\n", buf.toString());
    return 0;
}

Regards
Friedrich
Top | Discussion index | About this forum | D home