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:

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

Could you post your program's source code as well?

its a really long program, and im not sure where the error is coming from.

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

// runtime error
int A[10];
for(int i=0;i<=10;i++)
  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

// WRONG code:
char *A="Enter key"
std::cout<<"A == "<<A<<std::endl;
std::cin>>A;

This works if the entry is less than 9 characters long.

commented: Nice post, nice link :) +9

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:

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

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.

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++

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).

But Valgrind works only with Linux platforms and is not supporting detecting and localizing resource leaks such as memory, GDI and USER objects, handles.

yea, i ended up coming across it and fixing it... i think it was a delete vs delete[] statement somewhere

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).

I use it. Excellent tool:-O. Previously, I used Valgrind but is does not support search gdi leaks.:sad:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.