ouadji
Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
|
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"
;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
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)-
|