please take a look at the following code snippet:
#include <stdio.h>
int main ()
{
FILE * pFile;
pFile = fopen ("c:\\Temp\\test.txt","rb");
if (pFile!=NULL)
{
printf("opened\n");
fclose (pFile);
}
else{
printf("error\n");
}
return 0;
}
If I compile this code snippet and run it, nothing fails.
In case I execute the code in debug mode fopen fails with the following message:
Thread [1] 0 (Suspended : Signal : SIGSEGV:Segmentation fault)
wtoi64() at 0x77b35eab
wtoi64() at 0x77b35a70
ntdll!RtlpSetUserPreferredUILanguages() at 0x77ba5eff
ntdll!KiRaiseUserExceptionDispatcher() at 0x77b6a3ba
toi64() at 0x77b35a70
msvcrt!malloc() at 0x775c9d45
strcpy_s() at 0x775cf5d3
open_osfhandle() at 0x775d2b18
0x18
0xbf39e545
<...more frames...
Development environment:
Windows 7
Eclipse CDT Juno Service Release 1
MINGW 4.7
Compiler settings:
-O0 -g3 -Wall -c -fmessage-length=0
Does anybody have a clue why fopen fails in case I start the debugger and I execute each instruction step by step till fopen(..)?
Im looking forward for your answer. Thanks in advace.
I’ve solved the problem.
Before the fopen call I’Ve executed the following code:
The problem was, that memset was applied on 1024 bytes although just sizeof(size) bytes were allocated.
The subsequent fopen call chrashed due to a corrupted heap memory due to the previous used memset call on 1024 bytes.
Thanks so far!