943,623 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 915
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Jun 13th, 2009
0

Find cause of an error

Expand Post »
Hey, Ive been working on a program for a while, and once in a while it will crash for an unknown reason. I checked the error log and it says exception 0xc0000005 which means i'm writing somewhere i shouldn't. What are some common causes of this? Also is there anyway to use the fault offset to see where the error is (maybe in assembly?)... the error log says:
C++ Syntax (Toggle Plain Text)
  1. Faulting application Monitor 4 vc++.exe, version 0.0.0.0, time stamp 0x4a3262ca, faulting module ntdll.dll, version 6.0.6001.18000, time stamp 0x4791a7a6, exception code 0xc0000005, fault offset 0x00068bc0, process id 0x1588, application start time 0x01c9ebe1b60ba13c.

this may not be a c++ question but the program is in c++, i saw somewhere that it can be caused by using strlen on a non-null ended char array... is there anything else i should look for?
i can not cause this error, it just "happens" sommetimes
thanks
Similar Threads
Reputation Points: 10
Solved Threads: 8
Posting Whiz in Training
nschessnerd is offline Offline
216 posts
since Dec 2006
Jun 13th, 2009
0

Re: Find cause of an error

Could you post your program's source code as well?
Reputation Points: 2125
Solved Threads: 243
Postaholic
tux4life is offline Offline
2,105 posts
since Feb 2009
Jun 13th, 2009
0

Re: Find cause of an error

its a really long program, and im not sure where the error is coming from.
Reputation Points: 10
Solved Threads: 8
Posting Whiz in Training
nschessnerd is offline Offline
216 posts
since Dec 2006
Jun 13th, 2009
1

Re: Find cause of an error

If you don't want to post your code, then maybe a cut down version. But the quickest way to do it yourself is to compile with debug info on and then run and wait till it crashes. The backtrace will tell you what memory component has been corrupted. It may take a little to work out what has actually happened as another array may have over writen it. The debugger can help listing the symbol and memory addresses.

You can also try valgrind. http://valgrind.org. Which finds memory errors/leaks etc. [with a few false positives.] This is also very good at finding array boundary errors.

Typical things you will find are memory that is assigned but not deleted. Memory that is created with new but deleted with free() and vis-vera. Array over runs. e.g
c++ Syntax (Toggle Plain Text)
  1. // runtime error
  2. int A[10];
  3. for(int i=0;i<=10;i++)
  4. A[i]=i;
etc.
Similar things happen in char* because people overwrite the end of the array. If all the warnings are not on then you can do this
c++ Syntax (Toggle Plain Text)
  1. // WRONG code:
  2. char *A="Enter key"
  3. std::cout<<"A == "<<A<<std::endl;
  4. std::cin>>A;
This works if the entry is less than 9 characters long.
Last edited by StuXYZ; Jun 13th, 2009 at 5:06 pm.
Reputation Points: 732
Solved Threads: 134
Practically a Master Poster
StuXYZ is offline Offline
659 posts
since Nov 2008
Jun 14th, 2009
0

Re: Find cause of an error

hey, thanks for your response. Unfortounately i am developping for/on windows... however i did add a null byte to the end of a char* i was using strlen on. so far no crashes.. but they werent too common before
should i do the same when using <std::string>.length()?
block:
c++ Syntax (Toggle Plain Text)
  1. string buffer2="POST ";
  2. buffer2+=To_string(P.path);
  3. buffer2+=" HTTP/1.0\r\nHost: ";
  4. buffer2+=To_string(P.httpUrl);
  5. buffer2+="\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: ";
  6. std::stringstream outo;
  7. outo << ttPost->Length;
  8. buffer2+= outo.str();
  9. buffer2+="\r\n\r\n";
  10. buffer2+=To_string(ttPost);
  11. buffer2+="\n";
  12.  
  13. if(send(sock, buffer2.c_str(), buffer2.length(), 0)<buffer2.length()){//<--here
Last edited by nschessnerd; Jun 14th, 2009 at 12:33 am.
Reputation Points: 10
Solved Threads: 8
Posting Whiz in Training
nschessnerd is offline Offline
216 posts
since Dec 2006
Jun 14th, 2009
0

Re: Find cause of an error

I really don't think that the problem is with string. Examining you code fragment, buffer2 obviously has size (you could test this with a
std::cout<<"Length of buffer2 == "<<buffer2.length()<<std::endl;
You haven't done something horrible like have your own local version of string ?? and then the horrific using namespace std; that everyone seems to add has caused you some problems. Basically you are going to need to look at your debugger.
Last edited by StuXYZ; Jun 14th, 2009 at 5:16 pm.
Reputation Points: 732
Solved Threads: 134
Practically a Master Poster
StuXYZ is offline Offline
659 posts
since Nov 2008
Jun 15th, 2009
0

Re: Find cause of an error

i think i figured it out... im using System::string (m$) and i called delete [] String

yea... this is the first major app ive done in c++
Reputation Points: 10
Solved Threads: 8
Posting Whiz in Training
nschessnerd is offline Offline
216 posts
since Dec 2006
Jun 26th, 2009
0

Re: Find cause of an error

Click to Expand / Collapse  Quote originally posted by Mr_Smith ...
I used the Deleaker in such a case, and it always helped me to find not trivial errors and bugs.
<snip>
Deleaker costs money, and probably you even don't get as much features as the free Valgrind (as already mentioned in one of the previous posts).
Last edited by John A; Aug 8th, 2009 at 1:39 am. Reason: removed url from quote
Reputation Points: 2125
Solved Threads: 243
Postaholic
tux4life is offline Offline
2,105 posts
since Feb 2009
Jun 28th, 2009
1

Re: Find cause of an error

But Valgrind works only with Linux platforms and is not supporting detecting and localizing resource leaks such as memory, GDI and USER objects, handles.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Mr_Smith is offline Offline
2 posts
since Jun 2009
Jun 28th, 2009
0

Re: Find cause of an error

yea, i ended up coming across it and fixing it... i think it was a delete vs delete[] statement somewhere
Reputation Points: 10
Solved Threads: 8
Posting Whiz in Training
nschessnerd is offline Offline
216 posts
since Dec 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Restarting Application
Next Thread in C++ Forum Timeline: Memory Leaks





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC