T
The Doctor
Hey people,
I have a really weird problem.
I am developing a string class, just for fun. I am also writing an
application, which uses the string class, and uses a lot of them. But,
after about thirty String string = new String("blahblahblah"), I get the
following error:
*** glibc detected *** ./myapp: malloc(): memory corruption (fast):
0x080641f8 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6[0xb7bea962]
/lib/tls/i686/cmov/libc.so.6(__libc_malloc+0x8d)[0xb7bebcad]
/usr/lib/libLCore.so(_ZN7StringC1EPKc+0x4b)[0xb7eeafff]
../ka[0x804d3e4]
../ka[0x804b72a]
../ka(__gxx_personality_v0+0x3f4)[0x804b244]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe0)[0xb7b94450]
The code where the app crashes:
String::String(const char* other)
{
/*
allocate space for the actual string data, the Data structure
contains an int, which contains the length of the string, and a
pointer to a short array.
*/
d = (Data*)malloc(sizeof(Data));
/*
Allocate new data space, this is where the application crashes
*/
d->data = (short*)malloc(sizeof(short));
/*
Set the fist byte of the string to zero, the terminating 0 byte.
*/
d->size = 1;
memset(d->data, 0, sizeof(short));
/*
And append the other char array, with the append function.
*/
append(other);
}
I totally don't get my mistake. Does anyone of you knows what I am doing
wrong?
I have a really weird problem.
I am developing a string class, just for fun. I am also writing an
application, which uses the string class, and uses a lot of them. But,
after about thirty String string = new String("blahblahblah"), I get the
following error:
*** glibc detected *** ./myapp: malloc(): memory corruption (fast):
0x080641f8 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6[0xb7bea962]
/lib/tls/i686/cmov/libc.so.6(__libc_malloc+0x8d)[0xb7bebcad]
/usr/lib/libLCore.so(_ZN7StringC1EPKc+0x4b)[0xb7eeafff]
../ka[0x804d3e4]
../ka[0x804b72a]
../ka(__gxx_personality_v0+0x3f4)[0x804b244]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe0)[0xb7b94450]
The code where the app crashes:
String::String(const char* other)
{
/*
allocate space for the actual string data, the Data structure
contains an int, which contains the length of the string, and a
pointer to a short array.
*/
d = (Data*)malloc(sizeof(Data));
/*
Allocate new data space, this is where the application crashes
*/
d->data = (short*)malloc(sizeof(short));
/*
Set the fist byte of the string to zero, the terminating 0 byte.
*/
d->size = 1;
memset(d->data, 0, sizeof(short));
/*
And append the other char array, with the append function.
*/
append(other);
}
I totally don't get my mistake. Does anyone of you knows what I am doing
wrong?