Commit 52cde9b3 authored by Jon Griffiths's avatar Jon Griffiths Committed by Alexandre Julliard

StrRetToStrN returns BOOL and shouldn't crash on NULL dest.

parent 2eee7670
...@@ -44,16 +44,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(shell); ...@@ -44,16 +44,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(shell);
/************************* STRRET functions ****************************/ /************************* STRRET functions ****************************/
/* BOOL WINAPI StrRetToStrNA(LPSTR dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
* ***** NOTE *****
* These routines are identical to StrRetToBuf[AW] in dlls/shlwapi/string.c.
* They were duplicated here because not every version of Shlwapi.dll exports
* StrRetToBuf[AW]. If you change one routine, change them both. YOU HAVE BEEN
* WARNED.
* ***** NOTE *****
*/
HRESULT WINAPI StrRetToStrNA (LPVOID dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
{ {
TRACE("dest=%p len=0x%lx strret=%p(%s) pidl=%p\n", TRACE("dest=%p len=0x%lx strret=%p(%s) pidl=%p\n",
dest,len,src, dest,len,src,
...@@ -62,33 +53,36 @@ HRESULT WINAPI StrRetToStrNA (LPVOID dest, DWORD len, LPSTRRET src, const ITEMID ...@@ -62,33 +53,36 @@ HRESULT WINAPI StrRetToStrNA (LPVOID dest, DWORD len, LPSTRRET src, const ITEMID
(src->uType == STRRET_OFFSET) ? "STRRET_OFFSET" : "STRRET_???", (src->uType == STRRET_OFFSET) ? "STRRET_OFFSET" : "STRRET_???",
pidl); pidl);
if (!dest)
return FALSE;
switch (src->uType) switch (src->uType)
{ {
case STRRET_WSTR: case STRRET_WSTR:
WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, (LPSTR)dest, len, NULL, NULL); WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, dest, len, NULL, NULL);
CoTaskMemFree(src->u.pOleStr); CoTaskMemFree(src->u.pOleStr);
break; break;
case STRRET_CSTR: case STRRET_CSTR:
lstrcpynA((LPSTR)dest, src->u.cStr, len); lstrcpynA(dest, src->u.cStr, len);
break; break;
case STRRET_OFFSET: case STRRET_OFFSET:
lstrcpynA((LPSTR)dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len); lstrcpynA(dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len);
break; break;
default: default:
FIXME("unknown type!\n"); FIXME("unknown type!\n");
if (len) *(LPSTR)dest = '\0'; if (len) *dest = '\0';
return(FALSE); return FALSE;
} }
TRACE("-- %s\n", debugstr_a(dest) ); TRACE("-- %s\n", debugstr_a(dest) );
return S_OK; return TRUE;
} }
/************************************************************************/ /************************************************************************/
HRESULT WINAPI StrRetToStrNW (LPVOID dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl) BOOL WINAPI StrRetToStrNW(LPWSTR dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
{ {
TRACE("dest=%p len=0x%lx strret=%p(%s) pidl=%p\n", TRACE("dest=%p len=0x%lx strret=%p(%s) pidl=%p\n",
dest,len,src, dest,len,src,
...@@ -97,29 +91,32 @@ HRESULT WINAPI StrRetToStrNW (LPVOID dest, DWORD len, LPSTRRET src, const ITEMID ...@@ -97,29 +91,32 @@ HRESULT WINAPI StrRetToStrNW (LPVOID dest, DWORD len, LPSTRRET src, const ITEMID
(src->uType == STRRET_OFFSET) ? "STRRET_OFFSET" : "STRRET_???", (src->uType == STRRET_OFFSET) ? "STRRET_OFFSET" : "STRRET_???",
pidl); pidl);
if (!dest)
return FALSE;
switch (src->uType) switch (src->uType)
{ {
case STRRET_WSTR: case STRRET_WSTR:
lstrcpynW((LPWSTR)dest, src->u.pOleStr, len); lstrcpynW(dest, src->u.pOleStr, len);
CoTaskMemFree(src->u.pOleStr); CoTaskMemFree(src->u.pOleStr);
break; break;
case STRRET_CSTR: case STRRET_CSTR:
if (!MultiByteToWideChar( CP_ACP, 0, src->u.cStr, -1, dest, len ) && len) if (!MultiByteToWideChar( CP_ACP, 0, src->u.cStr, -1, dest, len ) && len)
((LPWSTR)dest)[len-1] = 0; dest[len-1] = 0;
break; break;
case STRRET_OFFSET: case STRRET_OFFSET:
if (!MultiByteToWideChar( CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset, -1, dest, len ) && len) if (!MultiByteToWideChar( CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset, -1, dest, len ) && len)
((LPWSTR)dest)[len-1] = 0; dest[len-1] = 0;
break; break;
default: default:
FIXME("unknown type!\n"); FIXME("unknown type!\n");
if (len) *(LPWSTR)dest = '\0'; if (len) *dest = '\0';
return(FALSE); return FALSE;
} }
return S_OK; return TRUE;
} }
...@@ -131,11 +128,12 @@ HRESULT WINAPI StrRetToStrNW (LPVOID dest, DWORD len, LPSTRRET src, const ITEMID ...@@ -131,11 +128,12 @@ HRESULT WINAPI StrRetToStrNW (LPVOID dest, DWORD len, LPSTRRET src, const ITEMID
* NOTES * NOTES
* the pidl is for STRRET OFFSET * the pidl is for STRRET OFFSET
*/ */
HRESULT WINAPI StrRetToStrNAW (LPVOID dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl) BOOL WINAPI StrRetToStrNAW(LPVOID dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
{ {
if(SHELL_OsIsUnicode()) if(SHELL_OsIsUnicode())
return StrRetToStrNW (dest, len, src, pidl); return StrRetToStrNW(dest, len, src, pidl);
return StrRetToStrNA (dest, len, src, pidl); else
return StrRetToStrNA(dest, len, src, pidl);
} }
/************************* OLESTR functions ****************************/ /************************* OLESTR functions ****************************/
......
...@@ -1201,7 +1201,7 @@ static LRESULT ShellView_OnNotify(IShellViewImpl * This, UINT CtlID, LPNMHDR lpn ...@@ -1201,7 +1201,7 @@ static LRESULT ShellView_OnNotify(IShellViewImpl * This, UINT CtlID, LPNMHDR lpn
} }
else /* LVN_GETDISPINFOW */ else /* LVN_GETDISPINFOW */
{ {
StrRetToStrNW( lpdi->item.pszText, lpdi->item.cchTextMax, &sd.str, NULL); StrRetToStrNW( ((NMLVDISPINFOW *)lpdi)->item.pszText, lpdi->item.cchTextMax, &sd.str, NULL);
TRACE("-- text=%s\n",debugstr_w((WCHAR*)(lpdi->item.pszText))); TRACE("-- text=%s\n",debugstr_w((WCHAR*)(lpdi->item.pszText)));
} }
} }
......
...@@ -119,23 +119,9 @@ LPITEMIDLIST WINAPI ILCreateFromPathAW(LPCVOID path); ...@@ -119,23 +119,9 @@ LPITEMIDLIST WINAPI ILCreateFromPathAW(LPCVOID path);
/* /*
string functions string functions
*/ */
HRESULT WINAPI StrRetToStrNA ( BOOL WINAPI StrRetToStrNA(LPSTR,DWORD,LPSTRRET,const ITEMIDLIST*);
LPVOID dest, BOOL WINAPI StrRetToStrNW(LPWSTR,DWORD,LPSTRRET,const ITEMIDLIST*);
DWORD len, BOOL WINAPI StrRetToStrNAW(LPVOID,DWORD,LPSTRRET,const ITEMIDLIST*);
LPSTRRET src,
const ITEMIDLIST *pidl);
HRESULT WINAPI StrRetToStrNW (
LPVOID dest,
DWORD len,
LPSTRRET src,
const ITEMIDLIST *pidl);
HRESULT WINAPI StrRetToStrNAW (
LPVOID dest,
DWORD len,
LPSTRRET src,
const ITEMIDLIST *pidl);
/**************************************************************************** /****************************************************************************
......
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