Note that there are some explanatory texts on larger screens.

plurals
  1. POVC++ 6.0 access violation when run in debugger
    text
    copied!<p>I am trying to add enhancements to a 4 year old VC++ 6.0 program. The debug build runs from the command line but not in the debugger: it crashes with an access violation inside printf(). If I skip the printf, then it crashes in malloc() (called from within fopen()) and I can't skip over that.</p> <p>This means I cannot run in the debugger and have to rely on the old printf statements to see what's going on. This obviously makes it a lot harder.</p> <p>Any idea why printf() and malloc() would fail when running under the VC++ debugger? I am no good at this low level stuff!</p> <p>Here is the call stack after the access violation:</p> <pre><code>_heap_alloc_dbg(unsigned int 24, int 2, const char * 0x0046b3d8 `string', int 225) line 394 + 8 bytes _nh_malloc_dbg(unsigned int 24, int 0, int 2, const char * 0x0046b3d8 `string', int 225) line 242 + 21 bytes _malloc_dbg(unsigned int 24, int 2, const char * 0x0046b3d8 `string', int 225) line 163 + 27 bytes _lock(int 2) line 225 + 19 bytes _getstream() line 55 + 7 bytes _fsopen(const char * 0x00468000 `string', const char * 0x00466280 `string', int 64) line 61 + 5 bytes fopen(const char * 0x00468000 `string', const char * 0x00466280 `string') line 104 + 15 bytes open_new_log(const char * 0x00468000 `string') line 66 + 14 bytes log_open(const char * 0x00468000 `string', int 0) line 106 + 9 bytes Xlog_open(const char * 0x00468000 `string', int 0) line 51 + 13 bytes service_start(unsigned long 1, char * * 0x009a0e50) line 3152 + 12 bytes service_init2(char * 0x00471fcc char * NTPROGRAM, char * 0x004723c4 char * NTSERVICE, char * 0x00466540 `string', unsigned long 1, char * * 0x009a0e50) line 508 + 13 bytes service_init(char * 0x00471fcc char * NTPROGRAM, char * 0x004723c4 char * NTSERVICE, unsigned long 2, char * * 0x009a0e50) line 548 main(unsigned long 2, char * * 0x009a0e50) line 3131 mainCRTStartup() line 206 + 25 bytes KERNEL32! 7c817067() </code></pre> <p>Here is the debug dissassembly up to the operation that fails:</p> <pre><code>0041EA7E jmp _heap_alloc_dbg+2B3h (0041eb23) 0041EA83 mov edx,dword ptr [_lTotalAlloc (004b4294)] 0041EA89 add edx,dword ptr [nSize] 0041EA8C mov dword ptr [_lTotalAlloc (004b4294)],edx 0041EA92 mov eax,[_lCurAlloc (004b429c)] 0041EA97 add eax,dword ptr [nSize] 0041EA9A mov [_lCurAlloc (004b429c)],eax 0041EA9F mov ecx,dword ptr [_lCurAlloc (004b429c)] 0041EAA5 cmp ecx,dword ptr [_lMaxAlloc (004b42a0)] 0041EAAB jbe _heap_alloc_dbg+249h (0041eab9) 0041EAAD mov edx,dword ptr [_lCurAlloc (004b429c)] 0041EAB3 mov dword ptr [_lMaxAlloc (004b42a0)],edx 0041EAB9 cmp dword ptr [_pFirstBlock (004b4298)],0 0041EAC0 je _heap_alloc_dbg+25Fh (0041eacf) 0041EAC2 mov eax,[_pFirstBlock (004b4298)] 0041EAC7 mov ecx,dword ptr [pHead] 0041EACA mov dword ptr [eax+4],ecx </code></pre> <p>Here is our source for that calls fopen() and fails in malloc()</p> <pre><code>FILE *open_new_log( const char *logfile ) { FILE *fp; int retry = 0; while( ( fp = fopen( logfile, "w" ) ) == NULL &amp;&amp; ++retry &lt; 300 ) Sleep( 1000 ); return( fp ); } </code></pre> <p>The error I get is</p> <pre><code>Unhandled exception inPISCOOP.exe: 0xC00000005: Access Violation </code></pre> <p>Regards,</p> <p>--- Alistair.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload