From: Dan Miner (dminer@nyx.cs.du.edu)
Date: 06/30/93


From: dminer@nyx.cs.du.edu (Dan Miner)
Subject: [FOLLOWUP:BUG? C++ lib]: C++ problem. (core dumps!)
Date: Wed, 30 Jun 1993 21:23:05 GMT


        I finally found the problem. In my OutputData object, it creates
an array on the free store (heap, please :). I have it were you can
change the size of the array with each instance of the class OutputData.
Well, I re-designed the interface to the class and I was using a function
the wasn't not yet initialized. In effect, I was doing a:

buf = (char *)malloc(0); !!! Oppps :)

Now what is interesting, the program WORKED fine until I did a:

free(buf);

(I got gdb to tell me more info) In the C lib (free.c lines 135-140), it
didn't check or something but it would die.
I know that malloc(0) is a no-no under Linux but it should have given me
a segmentation fault when writing to the buffer... Strange.

Thanks,
Dan

In article <1993Jun30.064720.18430@mnemosyne.cs.du.edu> dminer@nyx.cs.du.edu (Dan Miner) writes:
> I'm writing a uuencode/uudecode replacement program (ever
>smarter and better :). I'm doing it in C++. There is 6 main
>objects. A file Converter class, this class (template) takes
>5 other class for its data members.
>
>( actual order in the main() )
> Input i("./tmp", Input::Binary);
>// -Does input from a file and calls intType to store the data.
>
> Output o("-", Output::Text);
>// -Does the output to a file (including stdout). Gets its data
> from object outType.
>
> Convert c;
>// -The actual converter object. Calls intType and encodes data and
>// stores in outType.
>
> intType id(15, "./tmp");
>// -class for input data storage.
>
> outType od(15);
>// -class for output data storage.
>
> Converter < Convert, Input, intType, Output, outType >
> cv (c, i, id, o, od);
>// -The "wrapper" object. Calls input, Convert::process(), output.
>
>
>Here is what I get. (debug info)
>
>% p
> in setFileinfo
>in getELines()
>BeginV2.0 644 4089CB4A 2 ./tmp
>:=*E2BAG*RL@+5=A;&P@+4\R("UC("U$4$Q!5$9/4DT]54Y)6"!M86EN+D,*
>:=*E2A%G*RL@("UO('`@;6%I;BYO"BU$
>exiting run()
>in main!
> last meaningful statement
>OutputData dstor
>Segmentation fault (core dumped)
>
>[You can see. outType (typedef for class OutputData) is being
>destroy (a malloc()/free()). Wham! Here is gdb. I don't
>know how to use it and this is what I could get out of it.]
>
>% gdb p
>GDB is free software and you are welcome to distribute copies of it
> under certain conditions; type "show copying" to see the conditions.
>There is absolutely no warranty for GDB; type "show warranty" for details.
>GDB 4.6, Copyright 1992 Free Software Foundation, Inc...
>(no debugging symbols found)...
>(gdb) run
>Starting program: /users/dminer/shpmail/shpmail/p
>
>Program received signal 11, Segmentation fault
>0x60022b24 in ios::sync_with_stdio (Cannot access memory at address 0xdde85008.
>(gdb) quit
>The program is running. Quit anyway? (y or n)
>
>Is this a bugs in the C++ libs?
>
>If someone can tell me how to get more info out of gdb, please
>do! :)
>
>Thanks,
>Dan
>--
>Dan Miner (dminer@nyx.cs.du.edu)
>
>Hackers' Guide Coordinator for Linux
>"It all begins with a glimmer."