This site uses cookies to deliver our services and to show you relevant ads and job listings.
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.
Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these policies and terms.

Join us in building a kind, collaborative learning community via our updated
Code of Conduct.

It is important to note that all the methods presented here seem to work fine on their own, i.e. when I test them individually.

As you can see I have also overloaded the += operator. The problem is that whenever I use this operator, the next user input crashes the program when the splitString() function is called. The program crashes with the sole error message "terminate called recursively". No exceptions is thrown, nothing. Only an error code 0xC0000005

I can't really show you the entire code because the program got pretty big, currently about 1000 lines of code. I try to fix this program for hours and I have no idea what's going on. Any help is greatly appreciated !

This question appears to be off-topic. The users who voted to close gave this specific reason:

"Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Crazy Eddie, Sam Varshavchik, Prune, M.M

don't see a try catch block, how do you know it's not throwing? btw. terminate( ) is the indicator that it's throwing but you're not handling it catch( ... ) could help you with overlooked exception types
– deW1Oct 11 '16 at 22:26

I tried putting a try-catch over the entire main function and it caught nothing.
– AlanKalaneOct 11 '16 at 22:28

2

You're probably getting some kind of undefined behavior. There's not nearly enough code here to diagnose it. You'll probably need to step through the code with a debugger to narrow it down.
– Mark RansomOct 11 '16 at 22:32

1

You will need to learn how to use a debugger, and various development tools. Nobody else on stackoverflow.com can do it for you. Just because a program crashes at a particular point, that doesn't mean that's where the bug is, the bug can be anywhere, and knowing how to use a debugger, and various memory analysis tools like valgrind, is a required skill for every C++ developer.
– Sam VarshavchikOct 11 '16 at 22:37

also make sure you're not throwing an exception through any code compiled with -fno-exceptions.
– xaxxonOct 11 '16 at 22:41

1 Answer
1

The windows error code 0xC0000005 means STATUS_ACCESS_VIOLATION. This is typically caused by problem with pointers, out of bound array accesses, memory corruption and other serious issues.

The splitString() function looks ok, so it certainly not causes by itself the kind of behavior you're describing.

The operator+=() looks more suspicious. The code itself seems ok, but it makes assumptions that SetLength() changes the length, reallocates the pointer, and copies all the existing values, all without any problem. Note by the way that this code doesn't handle special case such as doing += on one self.

Unfortunately, the signature of this function is int SetLength(int length);. So the name of the parameter hides the name of the member length, which could cause some serious mismatches that could lead to buffer overflows or unchanged member length (unless you use this->length and length to make the difference between the two).

Finally, you are using raw pointers instead of smart pointers. So you must ensure the rule of 3. If you don't, you will end-up with shallow copies which could also lead to UB (when one of the object releases the memory that it's copy is still using).

You were right, somewhere in the setlength function i put this->length instead of length and it caused all the problems. Thank you, I was trying to fix this for hours and couldn't find the cause.
– AlanKalaneOct 12 '16 at 9:32

@AlanKalane good news! Would it be possible for the records to update your question with the code of SetLength() before you corrected it (in and edit section) ? This would be helpful for future readers having similar problems.
– ChristopheOct 12 '16 at 18:04