Carlo Bramini : shlwapi: Add NULL checks to StrCpyW and StrCatW.
Alexandre Julliard
julliard at winehq.org
Thu Apr 19 13:27:53 CDT 2012
Module: wine
Branch: master
Commit: f6524a9f77cfad6b2d6c7745cdc8598e50e4bdf4
URL: http://source.winehq.org/git/wine.git/?a=commit;h=f6524a9f77cfad6b2d6c7745cdc8598e50e4bdf4
Author: Carlo Bramini <carlo.bramix at libero.it>
Date: Wed Apr 18 21:51:05 2012 +0200
shlwapi: Add NULL checks to StrCpyW and StrCatW.
---
dlls/shlwapi/string.c | 6 ++++--
dlls/shlwapi/tests/string.c | 18 +++++++++++++++---
2 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/dlls/shlwapi/string.c b/dlls/shlwapi/string.c
index c65d576..e2f1cba 100644
--- a/dlls/shlwapi/string.c
+++ b/dlls/shlwapi/string.c
@@ -477,7 +477,8 @@ LPWSTR WINAPI StrCatW(LPWSTR lpszStr, LPCWSTR lpszSrc)
{
TRACE("(%s,%s)\n", debugstr_w(lpszStr), debugstr_w(lpszSrc));
- strcatW(lpszStr, lpszSrc);
+ if (lpszStr && lpszSrc)
+ strcatW(lpszStr, lpszSrc);
return lpszStr;
}
@@ -497,7 +498,8 @@ LPWSTR WINAPI StrCpyW(LPWSTR lpszStr, LPCWSTR lpszSrc)
{
TRACE("(%p,%s)\n", lpszStr, debugstr_w(lpszSrc));
- strcpyW(lpszStr, lpszSrc);
+ if (lpszStr && lpszSrc)
+ strcpyW(lpszStr, lpszSrc);
return lpszStr;
}
diff --git a/dlls/shlwapi/tests/string.c b/dlls/shlwapi/tests/string.c
index c918bcc..aac79f8 100644
--- a/dlls/shlwapi/tests/string.c
+++ b/dlls/shlwapi/tests/string.c
@@ -407,16 +407,28 @@ static void test_StrCpyW(void)
WCHAR szSrc[256];
WCHAR szBuff[256];
const StrFormatSizeResult* result = StrFormatSize_results;
-
+ LPWSTR lpRes;
while(result->value)
{
MultiByteToWideChar(0,0,result->byte_size_64,-1,szSrc,sizeof(szSrc)/sizeof(WCHAR));
- StrCpyW(szBuff, szSrc);
- ok(!StrCmpW(szSrc, szBuff), "Copied string %s wrong\n", result->byte_size_64);
+ lpRes = StrCpyW(szBuff, szSrc);
+ ok(!StrCmpW(szSrc, szBuff) && lpRes == szBuff, "Copied string %s wrong\n", result->byte_size_64);
result++;
}
+
+ /* this test crashes on win2k SP4 */
+ /*lpRes = StrCpyW(szBuff, NULL);*/
+ /*ok(lpRes == szBuff, "Wrong return value: got %p expected %p\n", lpRes, szBuff);*/
+
+ /* this test crashes on win2k SP4 */
+ /*lpRes = StrCpyW(NULL, szSrc);*/
+ /*ok(lpRes == NULL, "Wrong return value: got %p expected NULL\n", lpRes);*/
+
+ /* this test crashes on win2k SP4 */
+ /*lpRes = StrCpyW(NULL, NULL);*/
+ /*ok(lpRes == NULL, "Wrong return value: got %p expected NULL\n", lpRes);*/
}
static void test_StrChrNW(void)
More information about the wine-cvs
mailing list