flat assembler
Message board for the users of flat assembler.

Index > IDE Development > FASMW.ASM (bug)

Author
Thread Post new topic Reply to topic
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 02 Jul 2011, 20:21

i found a problem with the code of "fmsave" (FASMW.ASM)

IF "VirtualAlloc" fails (e.g. not enough memory),
THEN your file is lost! (size=0)

why ? because "CreateFile" is before "VirtualAlloc"

Code:
;original code
;-------------

fmsave:
 mov     [ei.header.mask],TCIF_PARAM
 invoke  SendMessage,[hwnd_tabctrl],TCM_GETITEM,[wparam],ei
  or      eax,eax
     jz      failed
      mov     eax,[ei.pszpath]
    or      eax,eax
     jz      failed
      invoke  CreateFile,eax,GENERIC_WRITE,0,0,CREATE_ALWAYS,0,0
  cmp     eax,-1
      je      failed
      mov     ebx,eax
     invoke  SendMessage,[ei.hwnd],WM_GETTEXTLENGTH,0,0
  inc     eax
 mov     [wparam],eax
        invoke  VirtualAlloc,0,eax,MEM_COMMIT,PAGE_READWRITE
        or      eax,eax
     jz      save_out_of_memory
  mov     [lparam],eax
        invoke  SendMessage,[ei.hwnd],WM_GETTEXT,[wparam],eax
       invoke  WriteFile,ebx,[lparam],eax,param_buffer,0
   invoke  CloseHandle,ebx
     ...
 ...
save_out_of_memory:
      invoke  CloseHandle,ebx
     jmp     failed
    

solution
Code:
fmsave:
       mov     [ei.header.mask],TCIF_PARAM
 invoke  SendMessage,[hwnd_tabctrl],TCM_GETITEM,[wparam],ei
  or      eax,eax
     jz      failed
      mov     ebx,[ei.pszpath]
    or      ebx,ebx
     jz      failed
      invoke  SendMessage,[ei.hwnd],WM_GETTEXTLENGTH,0,0
  inc     eax
 mov     [wparam],eax
        invoke  VirtualAlloc,0,eax,MEM_COMMIT,PAGE_READWRITE
        or      eax,eax
     jz      failed
      mov     [lparam],eax
        invoke  CreateFile,ebx,GENERIC_WRITE,0,0,CREATE_ALWAYS,0,0
  cmp     eax,-1
      je      CreateFileFails
     mov     ebx,eax
     invoke  SendMessage,[ei.hwnd],WM_GETTEXT,[wparam],[lparam]
  invoke  WriteFile,ebx,[lparam],eax,param_buffer,0
   invoke  CloseHandle,ebx
     ...
 ...
CreateFileFails:
 invoke  VirtualFree,[lparam],0,MEM_RELEASE
  jmp     failed
    


_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 02 Jul 2011, 20:21
View user's profile Send private message Send e-mail 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.