Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

call malloc exception

Status
Not open for further replies.

B1gBear

Programmer
Feb 5, 2007
2
0
0
CZ
Hi everybody, I'm working at school with inline assembler (in C++). I don't understand, where I could have a mistake.

My code:
Code:
#include <stdlib.h>

void blah()
{
      _asm {
            mov ecx, 4    // I'd like to allocate place for four pointers
            inc ecx          // in the end I'd like to NULL
            shl ecx, 2      // because of pointers, I have to multiply by four
            push ecx      // parameter on stack
            call malloc    // call malloc
            add esp, 4    // push parameter back
            // now I should have place for 20bytes in eax
      }
}

void main()
{
      blah();
}
This is problem, because this code breaks my application down. If I go through code in debugger, it throws me an unhandled exception after calling malloc, exactly it throws following:
Code:
„Unhandled exception at 0x004182c0 in app.exe: 0xC0000005: Access violation writing location 0x7ffe2486.“
Where is an error? Thank you.
 
It is solved. I'm using Visual Studio 2005 and standard functions are called from address table, so I have to call it in another way
Code:
call dword ptr malloc
or change properties of project :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top