From 4658e4d8dd4a0e533449b54e9e85ce4e0c902fd6 Mon Sep 17 00:00:00 2001 From: Juergen Schmied <juergen.schmied@metronet.de> Date: Sun, 22 Nov 1998 12:21:05 +0000 Subject: [PATCH] Fixes error handling (SetLastError() and return value). --- files/dos_fs.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/files/dos_fs.c b/files/dos_fs.c index 2fd9d6765cd..95414528e4b 100644 --- a/files/dos_fs.c +++ b/files/dos_fs.c @@ -845,14 +845,35 @@ BOOL32 DOSFS_GetFullName( LPCSTR name, BOOL32 check_last, DOS_FULL_NAME *full ) /*********************************************************************** * GetShortPathName32A (KERNEL32.271) + * + * NOTES + * observed: + * longpath=NULL: LastError=ERROR_INVALID_PARAMETER, ret=0 + * *longpath="" or invalid: LastError=ERROR_BAD_PATHNAME, ret=0 */ DWORD WINAPI GetShortPathName32A( LPCSTR longpath, LPSTR shortpath, DWORD shortlen ) { DOS_FULL_NAME full_name; + + if (!longpath) + { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + if (!longpath[0]) + { + SetLastError(ERROR_BAD_PATHNAME); + return 0; + } /* FIXME: is it correct to always return a fully qualified short path? */ - if (!DOSFS_GetFullName( longpath, TRUE, &full_name )) return 0; + if (!DOSFS_GetFullName( longpath, TRUE, &full_name )) + { + SetLastError(ERROR_BAD_PATHNAME); + return 0; + } lstrcpyn32A( shortpath, full_name.short_name, shortlen ); return strlen( full_name.short_name ); } @@ -865,8 +886,21 @@ DWORD WINAPI GetShortPathName32W( LPCWSTR longpath, LPWSTR shortpath, DWORD shortlen ) { DOS_FULL_NAME full_name; + LPSTR longpathA ; DWORD ret = 0; - LPSTR longpathA = HEAP_strdupWtoA( GetProcessHeap(), 0, longpath ); + + if (!longpath) + { SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + if (!longpath[0]) + { SetLastError(ERROR_BAD_PATHNAME); + return 0; + } + + + longpathA = HEAP_strdupWtoA( GetProcessHeap(), 0, longpath ); /* FIXME: is it correct to always return a fully qualified short path? */ if (DOSFS_GetFullName( longpathA, TRUE, &full_name )) @@ -874,8 +908,10 @@ DWORD WINAPI GetShortPathName32W( LPCWSTR longpath, LPWSTR shortpath, ret = strlen( full_name.short_name ); lstrcpynAtoW( shortpath, full_name.short_name, shortlen ); } + + SetLastError(ERROR_BAD_PATHNAME); HeapFree( GetProcessHeap(), 0, longpathA ); - return ret; + return 0; } -- GitLab