Question

I'm developing an algorithm based on Skyline queries using C++, using a RTree for storing my data. The algorithm works fine if I process up to 5 points then if I try 6 points it gives a segmentation fault. Using gdb I have discovered that the problem is here:

Program received signal SIGSEGV, Segmentation fault.
std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string (
    this=0x7fffffffd7c0, __str=
    <error reading variable: Cannot access memory at address 0xffffffffffffffe8>)
    at /usr/src/debug/gcc-4.7.2-20120921/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/include/bits/basic_string.tcc:175
175           __str.get_allocator())

Can anybody help me to understand where the error is or ar

Was it helpful?

Solution

Mitch Wheat already suggested this in a comment, but I think it is in fact the best answer for your problem, so:

Use valgrind.

Valgrind is a tool (or rather, a set of tools) for which the default mode of operation is to run your program and check for memory errors, such as leaks, buffer overruns, uninitialized reads, and more.

Literally all you need to do is to build your program, preferably with the -g option to make it easier to debug, and then run it like valgrind my-prog args.... Valgrind will then print out detailed error reports with stack traces when something bad is going on. Your problem here will likely be found without ever needing to use a regular debugger, nor have us guess at the problem (if this were my own problem, I'd use valgrind too).

OTHER TIPS

Given only that, my best guess is that you're trying to create a string using invalid source data, possibly a char pointer that's unitialized or that's pointing to a string that's already been freed

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top