Possible bug in poasm when a ret is inside an .IF

Started by shlomok, April 14, 2012, 02:00:02 PM

Previous topic - Next topic

shlomok

Hi,
Please refer to the full post here : http://www.masm32.com/board/index.php?topic=18690.0
but to sum up:
The following code will create an exe that always crashes when using Pelle's c to assemble and link it.
After inspecting the assembly it was clear that the first "ret" e.g. the one inside the .IF is the cause

allocateUsingHeapAlloc PROC  hHeap:DWORD, dwBytes:DWORD
                   
    invoke  HeapAlloc,hHeap, HEAP_ZERO_MEMORY,dwBytes
    .if eax == NULL
        invoke  StdOut,addr generalException
        mov     eax,FALSE
        ret
    .endif
    ret

allocateUsingHeapAlloc endp


The code runs smoothly using masm32.

Thanks,

hutch--

Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

i think that will crash, but for a different reason   :bg

shlomok

Quote from: dedndave on April 14, 2012, 02:45:58 PM
i think that will crash, but for a different reason   :bg

You are right, crash , different reason :)  see the screenshot.

What was the assumption behind the suggestion to use RETN?

qWord

it is a bug!
The folowing example has the same problem:
.686
.model flat, stdcall
option casemap :none

.code
main proc
    .if eax == 0
        ret
    .endif
    ret
main endp
end main

who will report it to pelle?

qWord
FPU in a trice: SmplMath
It's that simple!

dedndave

i elect Erol - lol
Erol may actually be Pelle in disguise (or the other way around)   :P

Quote from: shlomok on April 14, 2012, 03:46:32 PM
Quote from: dedndave on April 14, 2012, 02:45:58 PM
i think that will crash, but for a different reason   :bg

You are right, crash , different reason :)  see the screenshot.

What was the assumption behind the suggestion to use RETN?

when you use the meumonic "RET", the assembler assumes responsibility for typing it
and, if the epilogue is enabled, it also releases the stack frame and cleans up the stack parms, as required
the actual instructions are "RETN" for NEAR PROC's and "RETF" for FAR PROC's
there is also an IRET instruction, but that one must be explicit

you might try
        RETN    8
or whatever the appropriate number is

hutch--

If the RET only misbehaves within an .IF block, it probably has to do with the handling within the .IF block. To isolate what is happening with 2 RET instructions I would remove the block .IF and code it manually CMP/JE etc .... This will tell you if the problem is related to the .IF handling or not.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

shlomok

Quote from: hutch-- on April 15, 2012, 03:38:16 AM
If the RET only misbehaves within an .IF block, it probably has to do with the handling within the .IF block. To isolate what is happening with 2 RET instructions I would remove the block .IF and code it manually CMP/JE etc .... This will tell you if the problem is related to the .IF handling or not.

Is this what you had in mind?

allocateUsingHeapAlloc PROC hHeap:DWORD, dwBytes:DWORD                    
invoke  HeapAlloc,hHeap, HEAP_ZERO_MEMORY,dwBytes
test eax, NULL
jnz   @F
ret
      @@:
invoke StdOut, "xxx"
ret

allocateUsingHeapAlloc endp


this does not crash.

dedndave


Vortex

Hi shlomok,

The new Poasm version 7.00.0 has the same problem. I reported it in Pelles forum.

Vortex

Pelle fixed the bug. You need to download Pelles Macro Assembler, Version 7.00.3 released with PellesC V7.0, Release Candidate #2

shlomok

Quote from: Vortex on April 22, 2012, 05:58:29 PM
Pelle fixed the bug. You need to download Pelles Macro Assembler, Version 7.00.3 released with PellesC V7.0, Release Candidate #2

Hi thanks a lot!,
The latest version available on the website is version 7.02 RC1 dated 2012-04-15.

Where did you download version 7.03?

S.

Vortex

Hi shlomok,

You need to download the latest Pelles C development suit containing Poasm V7.00.3 :

http://www.smorgasbordet.com/pellesc/download.htm

http://www.smorgasbordet.com/pellesc/700/setup.exe

Pelle announced a new release candidate #2

shlomok

Quote from: Vortex on April 23, 2012, 08:12:49 AM
Hi shlomok,

You need to download the latest Pelles C development suit containing Poasm V7.00.3 :

http://www.smorgasbordet.com/pellesc/download.htm

http://www.smorgasbordet.com/pellesc/700/setup.exe

Pelle announced a new release candidate #2

Hi Vortex,
I was using: http://www.pellesc.de/index.php?page=download&lang=en

Didn't know about the link you provided. Thanks!

I can confirm that the bug was fixed (only tested the 32 bit version on a VM). So thanks to Pelle too.

Best,

S.