Find cause of an error

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Dec 2006
Posts: 201
Reputation: nschessnerd is an unknown quantity at this point 
Solved Threads: 8
nschessnerd's Avatar
nschessnerd nschessnerd is offline Offline
Posting Whiz in Training

Find cause of an error

 
0
  #1
Jun 13th, 2009
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:
  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
this.love(*);
&hea/rts;
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,969
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: Find cause of an error

 
0
  #2
Jun 13th, 2009
Could you post your program's source code as well?
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 201
Reputation: nschessnerd is an unknown quantity at this point 
Solved Threads: 8
nschessnerd's Avatar
nschessnerd nschessnerd is offline Offline
Posting Whiz in Training

Re: Find cause of an error

 
0
  #3
Jun 13th, 2009
its a really long program, and im not sure where the error is coming from.
this.love(*);
&hea/rts;
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 397
Reputation: StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light 
Solved Threads: 72
StuXYZ StuXYZ is offline Offline
Posting Whiz

Re: Find cause of an error

 
1
  #4
Jun 13th, 2009
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
  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
  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.
experience is the most expensive way to learn anything
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 201
Reputation: nschessnerd is an unknown quantity at this point 
Solved Threads: 8
nschessnerd's Avatar
nschessnerd nschessnerd is offline Offline
Posting Whiz in Training

Re: Find cause of an error

 
0
  #5
Jun 14th, 2009
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:
  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.
this.love(*);
&hea/rts;
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 397
Reputation: StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light 
Solved Threads: 72
StuXYZ StuXYZ is offline Offline
Posting Whiz

Re: Find cause of an error

 
0
  #6
Jun 14th, 2009
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.
experience is the most expensive way to learn anything
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 201
Reputation: nschessnerd is an unknown quantity at this point 
Solved Threads: 8
nschessnerd's Avatar
nschessnerd nschessnerd is offline Offline
Posting Whiz in Training

Re: Find cause of an error

 
0
  #7
Jun 15th, 2009
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++
this.love(*);
&hea/rts;
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,969
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: Find cause of an error

 
0
  #8
Jun 26th, 2009
Originally Posted by Mr_Smith View Post
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
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 2
Reputation: Mr_Smith is an unknown quantity at this point 
Solved Threads: 1
Mr_Smith Mr_Smith is offline Offline
Newbie Poster

Re: Find cause of an error

 
0
  #9
Jun 28th, 2009
But Valgrind works only with Linux platforms and is not supporting detecting and localizing resource leaks such as memory, GDI and USER objects, handles.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 201
Reputation: nschessnerd is an unknown quantity at this point 
Solved Threads: 8
nschessnerd's Avatar
nschessnerd nschessnerd is offline Offline
Posting Whiz in Training

Re: Find cause of an error

 
0
  #10
Jun 28th, 2009
yea, i ended up coming across it and fixing it... i think it was a delete vs delete[] statement somewhere
this.love(*);
&hea/rts;
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 655 | Replies: 9
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC