Hello,

writing code and studying the generated assembly with OllyDbg I have code that seems to compile to generate logically incorrect assembly. This happens in release mode ... in debug mode the assembly seems to be what I would expect. BTW I'm using VC++ 6 last service packed.

This is the code:

while((boRet = GetMessage(&sttMsg, NULL, 0, 0)) != 0)

{
if (boRet == -1)
{
// handle the error and possibly exit
}
else
{
if(!IsDialogMessage(g_hDlg, &sttMsg))
{
TranslateMessage(&sttMsg);
DispatchMessage(&sttMsg);
}
}
}



This code seems to produce the following:

004011EB PUSH 0 ;                       /MsgFilterMax = 0 

004011ED PUSH 0 ; |MsgFilterMin = 0
004011EF LEA EAX,DWORD PTR SS:[ESP+C] ; |
004011F3 PUSH 0 ; |hWnd = NULL
004011F5 PUSH EAX ; |pMsg
004011F6 CALL ESI ; \GetMessageA
004011F8 TEST EAX,EAX
004011FA JE SHORT Dummy.0040124A
004011FC PUSH EBX
004011FD MOV EBX,DWORD PTR DS:[<&USER32.DispatchM>; USER32.DispatchMessageA
00401203 PUSH EBP
00401204 MOV EBP,DWORD PTR DS:[<&USER32.IsDialogM>; USER32.IsDialogMessageA
0040120A PUSH EDI
0040120B MOV EDI,DWORD PTR DS:[<&USER32.Translate>; USER32.TranslateMessage
00401211 /CMP EAX,-1
00401214 |JE SHORT Dummy.00401236
00401216 |MOV EDX,DWORD PTR DS:[403048]
0040121C |LEA ECX,DWORD PTR SS:[ESP+10]
00401220 |PUSH ECX
00401221 |PUSH EDX
00401222 |CALL EBP
00401224 |TEST EAX,EAX
00401226 |JNZ SHORT Dummy.00401236
00401228 |LEA EAX,DWORD PTR SS:[ESP+10]
0040122C |PUSH EAX
0040122D |CALL EDI
0040122F |LEA ECX,DWORD PTR SS:[ESP+10]
00401233 |PUSH ECX
00401234 |CALL EBX
00401236 |PUSH 0
00401238 |PUSH 0
0040123A |LEA EDX,DWORD PTR SS:[ESP+18]
0040123E |PUSH 0
00401240 |PUSH EDX
00401241 |CALL ESI
00401243 |TEST EAX,EAX
00401245 \JNZ SHORT Dummy.00401211


Which I'd say is not correct since all the calls to GetMessage, IsDialogMessage, TranslateMessage and DispatchMessage seem to be outside of the loop.
Anyone got an idea?


yaa
Posted on 2004-01-09 12:47:19 by yaa
do you see:

CALL EBX ; func_ptr
CALL EDI ; func_ptr
..
etc ?

those are the function callers.
the code generated is fine, i think it is also optimized since it is using call <reg>
rather than:
call <offset>
...
...
offset:
jmp api_ptr

cheers
Posted on 2004-01-09 13:02:17 by wizzra
Sorry, I just noticed myself I said an enormous idiocy :stupid:

yaa
Posted on 2004-01-09 13:07:40 by yaa