0

[ altered ] I had a very strange bug. My debugger used to crash when it calls a function that uses an std::string. I thought this was an error iń my code and at first I didn't realized, that it had to do something with std::strings. Anyway I now know it has to do something with KDevelop, because if I compile this small test file:

#include <iostream>
#include <vector>
#include <string>

int main(int argc, char **argv) {
    std::cout << "Hello, world!" << std::endl;

    std::string test = "test test";
    std::cout << test;
    return 0;
}

It prints "test test" but when I try to debug it, it crashes as well at the call of main() . Anyway, I can debug my project with nemivar, which also uses GDB as backend, with no error.

So this isn't a problem to me anymore and this could be deleted.

Gellweiler
  • 751
  • 1
  • 12
  • 25
  • You should atleast provide us with the errors you are getting when it crashes. Try using a debugger. Without this information it will be hard to help without running your code which most people aren't going to do for you. – M. Laing Mar 21 '12 at 11:43
  • Can you tell us on what line it crashes? – Tony The Lion Mar 21 '12 at 11:44
  • The stupid thing is that the debugger doesn't print anything. – Gellweiler Mar 21 '12 at 11:48
  • When I jump into the function, I'm on the line: ResistanceNetwork::ResistanceNetwork( char *csv, char *start_signifier, char *end_signifier ) { There, I can see my variables, when I move one step ahead, the debugger crashes, how ever somehow sometimes the process still lives an I have to kill it in console. – Gellweiler Mar 21 '12 at 11:48
  • How is the `search_str_in_vector` function implemented? Could it be crashing there? BTW, the best help you can get here is from your debugger, run the code in the debugger and it will stop exactly where it crashes. (BTW, `p_start_point` and `p_end_point` are never initialized which is a bad idea) – David Rodríguez - dribeas Mar 21 '12 at 11:50
  • You should reduce this code down to the [**smallest possible** test-case](http://sscce.org). You will probably discover the problem in the process. – Oliver Charlesworth Mar 21 '12 at 11:58
  • I'm goinig to try this out, this sounds like a good idea. – Gellweiler Mar 21 '12 at 12:05
  • What does `ConnectionInNetwork::addPoint` do? – molbdnilo Mar 21 '12 at 12:13

1 Answers1

1

In your search_str_in_vector() function you dereference an end() iterator which is not allowed and results in undefined behaviour. Your for loop is also one element larger than the vector (start from vector.size()-1 instead).

uesp
  • 6,194
  • 20
  • 15
  • I set this answer as accepted answer, because my problem is now resolved and these tips helped me to clear out some other errors. – Gellweiler Mar 22 '12 at 15:44