From d519bc31155112bfcfb7eb5eb4c8384d148ccf97 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 29 Aug 2013 10:46:44 +0200 Subject: [PATCH] Fixed coverity issue 1047592 --- winpr/libwinpr/path/shell.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/winpr/libwinpr/path/shell.c b/winpr/libwinpr/path/shell.c index 0c41e54c0..1bf44f340 100644 --- a/winpr/libwinpr/path/shell.c +++ b/winpr/libwinpr/path/shell.c @@ -276,11 +276,14 @@ char* GetCombinedPath(char* basePath, char* subPath) int length; HRESULT status; char* path = NULL; - int basePathLength; - int subPathLength; + char* subPathCpy; + int basePathLength = 0; + int subPathLength = 0; - basePathLength = strlen(basePath); - subPathLength = strlen(subPath); + if (basePath) + basePathLength = strlen(basePath); + if (subPath) + subPathLength = strlen(subPath); length = basePathLength + subPathLength + 1; path = (char*) malloc(length + 1); @@ -293,12 +296,12 @@ char* GetCombinedPath(char* basePath, char* subPath) if (!subPath) return path; - subPath = _strdup(subPath); - PathCchConvertStyleA(subPath, subPathLength, PATH_STYLE_NATIVE); + subPathCpy = _strdup(subPath); + PathCchConvertStyleA(subPathCpy, subPathLength, PATH_STYLE_NATIVE); - status = NativePathCchAppendA(path, length + 1, subPath); + status = NativePathCchAppendA(path, length + 1, subPathCpy); - free(subPath); + free(subPathCpy); return path; }