mshtml: Don't write null byte in IPersist*::Save functions.

This commit is contained in:
Jacek Caban 2009-08-11 19:15:59 +02:00 committed by Alexandre Julliard
parent 0d5899548f
commit 520f41b259
1 changed files with 8 additions and 10 deletions

View File

@ -337,7 +337,7 @@ static HRESULT set_moniker(HTMLDocument *This, IMoniker *mon, IBindCtx *pibc, BO
return S_OK; return S_OK;
} }
static HRESULT get_doc_string(HTMLDocument *This, char **str, DWORD *len) static HRESULT get_doc_string(HTMLDocument *This, char **str)
{ {
nsIDOMNode *nsnode; nsIDOMNode *nsnode;
LPCWSTR strw; LPCWSTR strw;
@ -362,9 +362,7 @@ static HRESULT get_doc_string(HTMLDocument *This, char **str, DWORD *len)
nsAString_GetData(&nsstr, &strw); nsAString_GetData(&nsstr, &strw);
TRACE("%s\n", debugstr_w(strw)); TRACE("%s\n", debugstr_w(strw));
*len = WideCharToMultiByte(CP_ACP, 0, strw, -1, NULL, 0, NULL, NULL); *str = heap_strdupWtoA(strw);
*str = heap_alloc(*len);
WideCharToMultiByte(CP_ACP, 0, strw, -1, *str, *len, NULL, NULL);
nsAString_Finish(&nsstr); nsAString_Finish(&nsstr);
@ -583,7 +581,7 @@ static HRESULT WINAPI PersistFile_Save(IPersistFile *iface, LPCOLESTR pszFileNam
{ {
HTMLDocument *This = PERSISTFILE_THIS(iface); HTMLDocument *This = PERSISTFILE_THIS(iface);
char *str; char *str;
DWORD len, written=0; DWORD written=0;
HANDLE file; HANDLE file;
HRESULT hres; HRESULT hres;
@ -596,9 +594,9 @@ static HRESULT WINAPI PersistFile_Save(IPersistFile *iface, LPCOLESTR pszFileNam
return E_FAIL; return E_FAIL;
} }
hres = get_doc_string(This, &str, &len); hres = get_doc_string(This, &str);
if(SUCCEEDED(hres)) if(SUCCEEDED(hres))
WriteFile(file, str, len, &written, NULL); WriteFile(file, str, strlen(str), &written, NULL);
CloseHandle(file); CloseHandle(file);
return hres; return hres;
@ -698,16 +696,16 @@ static HRESULT WINAPI PersistStreamInit_Save(IPersistStreamInit *iface, LPSTREAM
{ {
HTMLDocument *This = PERSTRINIT_THIS(iface); HTMLDocument *This = PERSTRINIT_THIS(iface);
char *str; char *str;
DWORD len, written=0; DWORD written=0;
HRESULT hres; HRESULT hres;
TRACE("(%p)->(%p %x)\n", This, pStm, fClearDirty); TRACE("(%p)->(%p %x)\n", This, pStm, fClearDirty);
hres = get_doc_string(This, &str, &len); hres = get_doc_string(This, &str);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
hres = IStream_Write(pStm, str, len, &written); hres = IStream_Write(pStm, str, strlen(str), &written);
if(FAILED(hres)) if(FAILED(hres))
FIXME("Write failed: %08x\n", hres); FIXME("Write failed: %08x\n", hres);