From 68e5eb0709241968a1b91fb53e4c4cba27581a4a Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 9 Mar 2013 09:40:04 +0000 Subject: fix: PathToAbsolute doesn't clear the output string on error git-svn-id: http://svn.miranda-ng.org/main/trunk@3930 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/mir_core/path.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'src/mir_core') diff --git a/src/mir_core/path.cpp b/src/mir_core/path.cpp index 8c9dd6bacf..9e96c4348b 100644 --- a/src/mir_core/path.cpp +++ b/src/mir_core/path.cpp @@ -59,18 +59,22 @@ MIR_CORE_DLL(int) PathToRelative(const char *pSrc, char *pOut) MIR_CORE_DLL(int) PathToAbsolute(const char *pSrc, char *pOut, char* base) { - if ( !pSrc || !strlen(pSrc) || strlen(pSrc) > MAX_PATH) + if ( !pSrc || !strlen(pSrc) || strlen(pSrc) > MAX_PATH) { + *pOut = 0; return 0; - - if (base == NULL) - base = szMirandaPath; + } char buf[MAX_PATH]; if (pSrc[0] < ' ') return mir_snprintf(pOut, MAX_PATH, "%s", pSrc); - else if (pathIsAbsolute(pSrc)) + + if (pathIsAbsolute(pSrc)) return GetFullPathNameA(pSrc, MAX_PATH, pOut, NULL); - else if (pSrc[0] != '\\') + + if (base == NULL) + base = szMirandaPath; + + if (pSrc[0] != '\\') mir_snprintf(buf, MAX_PATH, "%s%s", base, pSrc); else mir_snprintf(buf, MAX_PATH, "%s%s", base, pSrc+1); @@ -141,22 +145,25 @@ MIR_CORE_DLL(int) PathToRelativeW(const WCHAR *pSrc, WCHAR *pOut) MIR_CORE_DLL(int) PathToAbsoluteW(const TCHAR *pSrc, TCHAR *pOut, TCHAR* base) { - if ( !pSrc || !wcslen(pSrc) || wcslen(pSrc) > MAX_PATH) + if ( !pSrc || !wcslen(pSrc) || wcslen(pSrc) > MAX_PATH) { + *pOut = 0; return 0; - - if (base == NULL) - base = szMirandaPathW; + } TCHAR buf[MAX_PATH]; if (pSrc[0] < ' ') return mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc); - else if (pathIsAbsoluteW(pSrc)) + + if (pathIsAbsoluteW(pSrc)) return GetFullPathName(pSrc, MAX_PATH, pOut, NULL); - else if (pSrc[0] != '\\') + + if (base == NULL) + base = szMirandaPathW; + + if (pSrc[0] != '\\') mir_sntprintf(buf, MAX_PATH, _T("%s%s"), base, pSrc); else mir_sntprintf(buf, MAX_PATH, _T("%s%s"), base, pSrc+1); - return GetFullPathName(buf, MAX_PATH, pOut, NULL); } -- cgit v1.2.3