| | |
Find cause of an error
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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:
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
C++ Syntax (Toggle Plain Text)
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;
&hea/rts;
•
•
Join Date: Nov 2008
Posts: 397
Reputation:
Solved Threads: 72
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
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
This works if the entry is less than 9 characters long.
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)
// runtime error int A[10]; for(int i=0;i<=10;i++) A[i]=i;
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)
// WRONG code: char *A="Enter key" std::cout<<"A == "<<A<<std::endl; std::cin>>A;
Last edited by StuXYZ; Jun 13th, 2009 at 5:06 pm.
experience is the most expensive way to learn anything
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:
should i do the same when using <std::string>.length()?
block:
c++ Syntax (Toggle Plain Text)
string buffer2="POST "; buffer2+=To_string(P.path); buffer2+=" HTTP/1.0\r\nHost: "; buffer2+=To_string(P.httpUrl); buffer2+="\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: "; std::stringstream outo; outo << ttPost->Length; buffer2+= outo.str(); buffer2+="\r\n\r\n"; buffer2+=To_string(ttPost); buffer2+="\n"; 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;
&hea/rts;
•
•
Join Date: Nov 2008
Posts: 397
Reputation:
Solved Threads: 72
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
You haven't done something horrible like have your own local version of string ?? and then the horrific
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
•
•
•
•
I used the Deleaker in such a case, and it always helped me to find not trivial errors and bugs.
<snip>
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."
![]() |
Similar Threads
- help me find the error. (PHP)
- Array C++ Help (C++)
- find the error (C++)
- Please help me to find error in this program .I am trying to add data to a dynamic ar (C++)
- Can Anyone find the error here? (C++)
- Check my code, There is 1 error, cant find it (C++)
- i neeed ur help .. find error in data structure program (C++)
- Can't find the error (C)
- help me find the error (C++)
- find out the error in my code (Java)
Other Threads in the C++ Forum
- Previous Thread: WinSock
- Next Thread: Undefined Reference to OpenGL functions!
Views: 655 | Replies: 9
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






