Commit 87bacf46 authored by Mike McCormack's avatar Mike McCormack Committed by Alexandre Julliard

Fix string conversion bugs.

parent 75d8be03
......@@ -206,16 +206,15 @@ HRESULT WINAPI AVIFileOpenA(PAVIFILE *ppfile, LPCSTR szFile, UINT uMode,
return AVIERR_BADPARAM;
/* convert ASCII string to Unicode and call unicode function */
len = lstrlenA(szFile);
len = MultiByteToWideChar(CP_ACP, 0, szFile, -1, NULL, 0);
if (len <= 0)
return AVIERR_BADPARAM;
wszFile = (LPWSTR)LocalAlloc(LPTR, (len + 1) * sizeof(WCHAR));
wszFile = (LPWSTR)LocalAlloc(LPTR, len * sizeof(WCHAR));
if (wszFile == NULL)
return AVIERR_MEMORY;
MultiByteToWideChar(CP_ACP, 0, szFile, -1, wszFile, len + 1);
wszFile[len + 1] = 0;
MultiByteToWideChar(CP_ACP, 0, szFile, -1, wszFile, len);
hr = AVIFileOpenW(ppfile, wszFile, uMode, lpHandler);
......@@ -1563,16 +1562,15 @@ HRESULT WINAPI AVISaveVA(LPCSTR szFile, CLSID *pclsidHandler,
return AVIERR_BADPARAM;
/* convert ASCII string to Unicode and call Unicode function */
len = lstrlenA(szFile);
len = MultiByteToWideChar(CP_ACP, 0, szFile, -1, NULL, 0);
if (len <= 0)
return AVIERR_BADPARAM;
wszFile = (LPWSTR)LocalAlloc(LPTR, (len + 1) * sizeof(WCHAR));
wszFile = LocalAlloc(LPTR, len * sizeof(WCHAR));
if (wszFile == NULL)
return AVIERR_MEMORY;
MultiByteToWideChar(CP_ACP, 0, szFile, -1, wszFile, len + 1);
wszFile[len + 1] = 0;
MultiByteToWideChar(CP_ACP, 0, szFile, -1, wszFile, len);
hr = AVISaveVW(wszFile, pclsidHandler, lpfnCallback,
nStream, ppavi, plpOptions);
......
......@@ -47,6 +47,7 @@
#include "avifile_private.h"
#include "extrachunk.h"
#include "wine/unicode.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(avifile);
......@@ -640,7 +641,11 @@ static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile *iface,
MMIO_ALLOCBUF | dwMode);
if (This->paf->hmmio == NULL) {
/* mmioOpenW not in native DLLs of Win9x -- try mmioOpenA */
LPSTR szFileName = LocalAlloc(LPTR, len * sizeof(CHAR));
LPSTR szFileName;
len = WideCharToMultiByte(CP_ACP, 0, This->paf->szFileName, -1,
NULL, 0, NULL, NULL);
szFileName = LocalAlloc(LPTR, len * sizeof(CHAR));
if (szFileName == NULL)
return AVIERR_MEMORY;
......@@ -698,13 +703,13 @@ static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile *iface,
assert(This->paf != NULL);
if (This->paf->szFileName != NULL) {
int len = lstrlenW(This->paf->szFileName);
int len = lstrlenW(This->paf->szFileName) + 1;
*ppszFileName = (LPOLESTR)GlobalAllocPtr(GHND, len * sizeof(WCHAR));
if (*ppszFileName == NULL)
return AVIERR_MEMORY;
memcpy(*ppszFileName, This->paf->szFileName, len * sizeof(WCHAR));
strcpyW(*ppszFileName, This->paf->szFileName);
}
return AVIERR_OK;
......
......@@ -34,6 +34,7 @@
#include "avifile_private.h"
#include "extrachunk.h"
#include "wine/unicode.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(avifile);
......@@ -583,7 +584,7 @@ static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile *iface,
This->uMode = dwMode;
len = lstrlenW(pszFileName) + 1;
This->szFileName = (LPWSTR)LocalAlloc(LPTR, len * sizeof(WCHAR));
This->szFileName = LocalAlloc(LPTR, len * sizeof(WCHAR));
if (This->szFileName == NULL)
return AVIERR_MEMORY;
lstrcpyW(This->szFileName, pszFileName);
......@@ -592,7 +593,10 @@ static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile *iface,
This->hmmio = mmioOpenW(This->szFileName, NULL, MMIO_ALLOCBUF | dwMode);
if (This->hmmio == NULL) {
/* mmioOpenW not in native DLLs of Win9x -- try mmioOpenA */
LPSTR szFileName = LocalAlloc(LPTR, len * sizeof(CHAR));
LPSTR szFileName;
len = WideCharToMultiByte(CP_ACP, 0, This->szFileName, -1,
NULL, 0, NULL, NULL);
szFileName = LocalAlloc(LPTR, len * sizeof(CHAR));
if (szFileName == NULL)
return AVIERR_MEMORY;
......@@ -659,13 +663,13 @@ static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile *iface,
assert(This->paf != NULL);
if (This->paf->szFileName != NULL) {
int len = lstrlenW(This->paf->szFileName);
int len = lstrlenW(This->paf->szFileName) + 1;
*ppszFileName = (LPOLESTR)GlobalAllocPtr(GHND, len * sizeof(WCHAR));
*ppszFileName = GlobalAllocPtr(GHND, len * sizeof(WCHAR));
if (*ppszFileName == NULL)
return AVIERR_MEMORY;
memcpy(*ppszFileName, This->paf->szFileName, len * sizeof(WCHAR));
strcpyW(*ppszFileName, This->paf->szFileName);
}
return AVIERR_OK;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment