Hello :)

My program is supposed to load some data into a buffer - but it fails.
This is where i get a segmentation fault...

char* buf = new char[size + 2];

Where my debugging tells me that size is correctly containing the value "1957" which is the actual size of the file I'm loading.

I have absolutely no clue why this is happening - my only guess is that the class that calls the code above, isn't instanced... But that doesn't seem to be the problem, as the this value seem sane:

(this=0x7fffffffe010,handler=<value optimized out>,filename=@0x7fffffffe1e0: {static npos = 18446744073709551615, d_cplength = 22, d_reserve = 32, d_encodedbuff = 0x8bc4f0 "MyGUI.scheme", d_encodeddatlen = 23, d_encodedbufflen = 23, d_quickbuff = {66, 108, 97, 110, 121, 101, 69, 110, 103, 105, 110, 101, 71, 85, 73, 46, 115, 99, 104, 101, 109, 101, 0, 0, 0, 1, 6512536, 0, 4152271862, 32767, 6512600, 0}, d_buffer = 0x0},resourceGroup=@0x7fffffffe290: {static npos = 18446744073709551615, d_cplength = 3, d_reserve = 32, d_encodedbuff = 0x8c4d00 "GUI", d_encodeddatlen = 4, d_encodedbufflen = 4, d_quickbuff = {71, 85, 73, 0, 4160565248, 32767, 6512952, 0, 4160569344, 32767, 6513000, 0, 4294967295, 0, 6513064, 0, 4152131584, 32767, 6513128, 0, 4155236576, 32767, 6513176, 0, 4155237048, 32767, 6513240, 0, 4158575052, 32767, 6513304, 0}, d_buffer = 0x0}

Any clues? :) Thanks!

Recommended Answers

All 4 Replies

could you please post the code that uses this line.

The heap got corrupted somewhere else.
Looks like you are using arrays. Make sure there's no overruns, or any other writes beyond the allocated memory, or double deletes, etc, etc, etc. After you find the problem, dump arrays altogether and rewrite everything with vectors.

commented: Well said +20

Any specific? Theres a lot of code on the Call Stack..

d_handler = &handler;

        RawDataContainer rawXMLData;
        System::getSingleton().getResourceProvider()->loadRawDataContainer(filename, rawXMLData, resourceGroup);

        // Create a buffer with extra bytes for a newline and a terminating null
        size_t size = rawXMLData.getSize(); // debugger says 1957
        char* buf = new char[size + 2];
        memcpy(buf, rawXMLData.getDataPtr(), size);
        buf[size] = '\n';
        buf[size+1] = 0;

The heap got corrupted somewhere else.
Looks like you are using arrays. Make sure there's no overruns, or any other writes beyond the allocated memory, or double deletes, etc, etc, etc. After you find the problem, dump arrays altogether and rewrite everything with vectors.

thank you for your reply - I'll look for what you described tomorrow and get back to you later. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.