[SHLWAPI][SHLWAPI_APITEST] Fix NULL behavior of StrDupA/W (#6720)

Fix wrong behavior of shlwapi!StrDupA and shlwapi!StrDupW functions.
JIRA issue: CORE-19495
Return NULL when lpszStr == NULL.
This commit is contained in:
Katayama Hirofumi MZ 2024-04-08 09:17:08 +09:00 committed by GitHub
parent 0cfc9aba05
commit ff531eaade
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 57 additions and 0 deletions

View file

@ -1068,6 +1068,10 @@ LPSTR WINAPI StrDupA(LPCSTR lpszStr)
TRACE("(%s)\n",debugstr_a(lpszStr)); TRACE("(%s)\n",debugstr_a(lpszStr));
#ifdef __REACTOS__
if (!lpszStr)
return NULL;
#endif
iLen = lpszStr ? strlen(lpszStr) + 1 : 1; iLen = lpszStr ? strlen(lpszStr) + 1 : 1;
lpszRet = LocalAlloc(LMEM_FIXED, iLen); lpszRet = LocalAlloc(LMEM_FIXED, iLen);
@ -1093,6 +1097,10 @@ LPWSTR WINAPI StrDupW(LPCWSTR lpszStr)
TRACE("(%s)\n",debugstr_w(lpszStr)); TRACE("(%s)\n",debugstr_w(lpszStr));
#ifdef __REACTOS__
if (!lpszStr)
return NULL;
#endif
iLen = (lpszStr ? strlenW(lpszStr) + 1 : 1) * sizeof(WCHAR); iLen = (lpszStr ? strlenW(lpszStr) + 1 : 1) * sizeof(WCHAR);
lpszRet = LocalAlloc(LMEM_FIXED, iLen); lpszRet = LocalAlloc(LMEM_FIXED, iLen);

View file

@ -17,6 +17,7 @@ list(APPEND SOURCE
SHLoadIndirectString.c SHLoadIndirectString.c
SHLoadRegUIString.c SHLoadRegUIString.c
SHPropertyBag.cpp SHPropertyBag.cpp
StrDup.c
StrFormatByteSizeW.c StrFormatByteSizeW.c
testdata.rc testdata.rc
testlist.c) testlist.c)

View file

@ -0,0 +1,46 @@
/*
* PROJECT: ReactOS api tests
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Tests for StrDupA/W
* COPYRIGHT: Copyright 2024 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
*/
#include <apitest.h>
#include <shlwapi.h>
#include <versionhelpers.h>
static void TEST_StrDupA(void)
{
LPSTR ptrA;
ptrA = StrDupA(NULL);
if (IsWindowsXPOrGreater())
ok_ptr(ptrA, NULL);
else
ok(ptrA && !*ptrA, "ptrA: '%s'\n", wine_dbgstr_a(ptrA));
if (ptrA)
LocalFree(ptrA);
}
static void TEST_StrDupW(void)
{
LPWSTR ptrW;
ptrW = StrDupW(NULL);
if (IsWindowsXPOrGreater())
ok_ptr(ptrW, NULL);
else
ok(ptrW && !*ptrW, "ptrW: '%s'\n", wine_dbgstr_w(ptrW));
if (ptrW)
LocalFree(ptrW);
}
START_TEST(StrDup)
{
TEST_StrDupA();
TEST_StrDupW();
}

View file

@ -13,6 +13,7 @@ extern void func_SHGetRestriction(void);
extern void func_SHLoadIndirectString(void); extern void func_SHLoadIndirectString(void);
extern void func_SHLoadRegUIString(void); extern void func_SHLoadRegUIString(void);
extern void func_SHPropertyBag(void); extern void func_SHPropertyBag(void);
extern void func_StrDup(void);
extern void func_StrFormatByteSizeW(void); extern void func_StrFormatByteSizeW(void);
const struct test winetest_testlist[] = const struct test winetest_testlist[] =
@ -29,6 +30,7 @@ const struct test winetest_testlist[] =
{ "SHLoadIndirectString", func_SHLoadIndirectString }, { "SHLoadIndirectString", func_SHLoadIndirectString },
{ "SHLoadRegUIString", func_SHLoadRegUIString }, { "SHLoadRegUIString", func_SHLoadRegUIString },
{ "SHPropertyBag", func_SHPropertyBag }, { "SHPropertyBag", func_SHPropertyBag },
{ "StrDup", func_StrDup },
{ "StrFormatByteSizeW", func_StrFormatByteSizeW }, { "StrFormatByteSizeW", func_StrFormatByteSizeW },
{ 0, 0 } { 0, 0 }
}; };