"large" project, crashes, variable "overlap", gdb

hello,
i searching for days for an Segmentation fault.

What i ve done:
i try:
- valgrind
- gdb
- comment the most c++ code out

my problem, if i comment out one more header i got an Segmentation fault.
i try different headers, always the same.
-> some more code -> crash (which header i comment out, is equal)

i try to rebuild the error, create an new project, copy the source code, run...
all okay. i can not replicate the error, with "new" source code. *argh*


my cood looks like

<code>
#include <iostream>
#include <vector>

class interface{
public:
void init(void);
private:
std::vector<unsigned char> m_data;
};

void interface::init()
{
m_data.clear();
m_data.resize(8192);
}

class m;

class minterface : public interface{
public:
minterface();
void init(m* value);
private:
m* m_ptr;
};

minterface::minterface()
{
m_ptr = nullptr;
}

void minterface::init(m* value)
{
m_ptr = value;
interface::init();
}

class m{
public:
void init(void);
private:
minterface m_i;
};

void m::init(void)
{
m_i.init(this);
}

int main() {
m a;
a.init();
return 0;
}
</code>

if i got an segmentation fault the address from the variable m_ptr is too close to the m_data,
check my gdb out:
(gdb) break minterface::init
(gdb) r
(gdb) print m_data
$1 = std::vector of length 0, capacity 0
(gdb) print &m_data
$2 = (std::vector<unsigned char, std::allocator<unsigned char> > *) 0xbefffc8c
(gdb) print m_ptr
$3 = (m_ptr *) 0x0
(gdb) print &m_ptr
$4 = (m_ptr **) 0xbefffc8c

after i set the m_ptr variable i got this output:

(gdb) print m_ptr
$7 = (m_ptr *) 0xbefff9dc
(gdb) print m_data
$8 = std::vector of length 1090520612, capacity 1090520612 = {132 '\204', 24 '\030', 4 '\004', 0 '\000', 8 '\b', 49 '1', 6 '\006', 0 '\000', 0 '\000', 0 '\000', 0 '\000',
0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 248 '\370', 249 '\371', 255 '\377', 190 '\276', 0 '\000', 0 '\000', 0 '\000', 0 '\000',
0 '\000', 0 '\000', 0 '\000', 0 '\000', 32 ' ', 2 '\002', 0 '\000', 0 '\000', 8 '\b', 0 '\000', 0 '\000', 0 '\000', 66 'B', 0 '\000', 0 '\000', 0 '\000', 16 '\020', 250 '\372',
255 '\377', 190 '\276', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 124 '|', 0 '\000', 0 '\000',
0 '\000', 16 '\020', 1 '\001', 0 '\000', 0 '\000', 40 '(', 250 '\372', 255 '\377', 190 '\276', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 53 '5', 255 '\377', 182 '\266',
0 '\000', 48 '0', 226 '\342', 182 '\266', 9 '\t', 2 '\002', 0 '\000', 0 '\000', 64 '@', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 68 'D', 250 '\372',
255 '\377', 190 '\276', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 49 '1', 216 '\330', 182 '\266', 9 '\t', 2 '\002', 0 '\000', 0 '\000', 0 '\000', 150 '\226', 104 'h',
126 '~', 4 '\004', 1 '\001', 0 '\000', 0 '\000', 92 '\\', 250 '\372', 255 '\377', 190 '\276', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000',
4 '\004', 1 '\001', 0 '\000', 0 '\000', 244 '\364', 251 '\373', 255 '\377', 190 '\276', 16 '\020', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 59 ';', 8 '\b', 0 '\000', 0 '\000',
0 '\000', 0 '\000', 0 '\000', 124 '|', 250 '\372', 255 '\377', 190 '\276', 11 '\v', 0 '\000', 0 '\000', 0 '\000', 83 'S', 101 'e', 99 'c', 116 't', 105 'i', 111 'o', 110 'n',
108 'l', 101 'e', 115 's', 115 's', 0 '\000', 116 't', 7 '\a', 4 '\004', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000',
0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000', 0 '\000'...}
(gdb)

m_data is corrupted :-(

Have anybody some idea?

thanks a lot!
The code that you have posted does not contain any header files.

If the segfault only happens when you change the code, never after a fresh build, then maybe there is something wrong with how your build process is set up. When a header file is modified all .cpp files that includes that header file (either directly or indirectly through another header) needs to be recompiled.
Last edited on
Topic archived. No new replies allowed.