Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

call malloc exception

call malloc exception

call malloc exception

Hi everybody, I'm working at school with inline assembler (in C++). I don't understand, where I could have a mistake.

My 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()
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:


„Unhandled exception at 0x004182c0 in app.exe: 0xC0000005: Access violation writing location 0x7ffe2486."
Where is an error? Thank you.

RE: call malloc exception

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


call dword ptr malloc
or change properties of project smile

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close