winpr: fix PathCchAppend
Fix incorrect usage of S_FALSE which was used to indicate errors although it is a HRESULT success code. Make this function behave like the Windows 8 implementation and the according MSDN specification. - return E_INVALIDARG instead of S_FALSE if pszPath is NULL - return E_INVALIDARG instead of S_FALSE if pszMore is NULL - return E_INVALIDARG if cchPath is zero - return E_INVALIDARG if cchPath is greater than PATHCCH_MAX_CCH - return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE) if the combined path size exceeds cchPath (this is the same HRESULT which the Windows implementation returns in this case and which is referred to as PATHCCH_E_FILENAME_TOO_LONG on msdn) Also extended/fixed the TestPathCchAppend ctest
This commit is contained in:
parent
92b0076c53
commit
178afd8dd5
@ -17,10 +17,13 @@ HRESULT PATH_CCH_APPEND(PWSTR pszPath, size_t cchPath, PCWSTR pszMore)
|
||||
size_t pszPathLength;
|
||||
|
||||
if (!pszPath)
|
||||
return S_FALSE;
|
||||
return E_INVALIDARG;
|
||||
|
||||
if (!pszMore)
|
||||
return S_FALSE;
|
||||
return E_INVALIDARG;
|
||||
|
||||
if (cchPath == 0 || cchPath > PATHCCH_MAX_CCH)
|
||||
return E_INVALIDARG;
|
||||
|
||||
pszMoreLength = lstrlenW(pszMore);
|
||||
pszPathLength = lstrlenW(pszPath);
|
||||
@ -54,7 +57,7 @@ HRESULT PATH_CCH_APPEND(PWSTR pszPath, size_t cchPath, PCWSTR pszMore)
|
||||
}
|
||||
#endif
|
||||
|
||||
return S_FALSE;
|
||||
return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);
|
||||
}
|
||||
|
||||
#else
|
||||
@ -67,10 +70,13 @@ HRESULT PATH_CCH_APPEND(PSTR pszPath, size_t cchPath, PCSTR pszMore)
|
||||
size_t pszPathLength;
|
||||
|
||||
if (!pszPath)
|
||||
return S_FALSE;
|
||||
return E_INVALIDARG;
|
||||
|
||||
if (!pszMore)
|
||||
return S_FALSE;
|
||||
return E_INVALIDARG;
|
||||
|
||||
if (cchPath == 0 || cchPath > PATHCCH_MAX_CCH)
|
||||
return E_INVALIDARG;
|
||||
|
||||
pszMoreLength = lstrlenA(pszMore);
|
||||
pszPathLength = lstrlenA(pszPath);
|
||||
@ -103,7 +109,7 @@ HRESULT PATH_CCH_APPEND(PSTR pszPath, size_t cchPath, PCSTR pszMore)
|
||||
}
|
||||
}
|
||||
|
||||
return S_FALSE;
|
||||
return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -15,6 +15,7 @@ int TestPathCchAppend(int argc, char* argv[])
|
||||
{
|
||||
HRESULT status;
|
||||
TCHAR Path[PATHCCH_MAX_CCH];
|
||||
size_t i;
|
||||
|
||||
/* Base Path: Backslash, More Path: No Backslash */
|
||||
|
||||
@ -88,6 +89,53 @@ int TestPathCchAppend(int argc, char* argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* According to msdn a NULL Path is an invalid argument */
|
||||
status = PathCchAppend(NULL, PATHCCH_MAX_CCH, testMorePathNoBackslash);
|
||||
if (status != E_INVALIDARG)
|
||||
{
|
||||
_tprintf(_T("PathCchAppend with NULL path unexpectedly returned status: 0x%08X\n"), status);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* According to msdn a NULL pszMore is an invalid argument (although optional !?) */
|
||||
_tcscpy(Path, testBasePathNoBackslash);
|
||||
status = PathCchAppend(Path, PATHCCH_MAX_CCH, NULL);
|
||||
if (status != E_INVALIDARG)
|
||||
{
|
||||
_tprintf(_T("PathCchAppend with NULL pszMore unexpectedly returned status: 0x%08X\n"), status);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* According to msdn cchPath must be > 0 and <= PATHCCH_MAX_CCH */
|
||||
_tcscpy(Path, testBasePathNoBackslash);
|
||||
status = PathCchAppend(Path, 0, testMorePathNoBackslash);
|
||||
if (status != E_INVALIDARG)
|
||||
{
|
||||
_tprintf(_T("PathCchAppend with cchPath value 0 unexpectedly returned status: 0x%08X\n"), status);
|
||||
return -1;
|
||||
}
|
||||
_tcscpy(Path, testBasePathNoBackslash);
|
||||
status = PathCchAppend(Path, PATHCCH_MAX_CCH + 1, testMorePathNoBackslash);
|
||||
if (status != E_INVALIDARG)
|
||||
{
|
||||
_tprintf(_T("PathCchAppend with cchPath value > PATHCCH_MAX_CCH unexpectedly returned status: 0x%08X\n"), status);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Resulting file must not exceed PATHCCH_MAX_CCH */
|
||||
|
||||
for (i = 0; i < PATHCCH_MAX_CCH - 1; i++)
|
||||
Path[i] = _T('X');
|
||||
|
||||
Path[PATHCCH_MAX_CCH - 1] = 0;
|
||||
|
||||
status = PathCchAppend(Path, PATHCCH_MAX_CCH, _T("\\This cannot be appended to Path"));
|
||||
if (SUCCEEDED(status))
|
||||
{
|
||||
_tprintf(_T("PathCchAppend unexepectedly succeeded with status: 0x%08X\n"), status);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user