flat assembler
Message board for the users of flat assembler.

Index > Windows > is that correct?

Author
Thread Post new topic Reply to topic
zxcv
Guest




zxcv 13 Jan 2008, 18:50
im litle tired, and i just want to be sure. I never did it before:
Code:
push 512
call [malloc]
mov [wsadata], eax
add eax, 400
mov [buffer], eax ;buffer has space for 112 bytes
push MEM
call [free]
add esp, 8
retn    

...
Code:
MEM:
wsadata dd ?
buffer dd ?    

is that correct? or i forgot about something?
Post 13 Jan 2008, 18:50
Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 13 Jan 2008, 19:09
No it is not, you are freeing "MEM" address which was never allocated by malloc but by program loader. Since you store the address returned by malloc at [wsadata], you should do "push [wsadata]/call [free]" instead.
Post 13 Jan 2008, 19:09
View user's profile Send private message Reply with quote
zxcv
Guest




zxcv 13 Jan 2008, 21:00
yes, ur right. i always used stack for it, but sometimes it went too complicated and i had to write from beggining Smile
8 bytes in almost empty section isnt much.
Post 13 Jan 2008, 21:00
Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 13 Jan 2008, 21:35
Why do you use hardcoded magic values instead of sizeof?
Post 13 Jan 2008, 21:35
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.