diff --git a/main/options.c b/main/options.c index 1c54b78c42..d2b0572162 100644 --- a/main/options.c +++ b/main/options.c @@ -3522,7 +3522,7 @@ static char* prependEnvvar (const char *path, const char* envvar) char *full_path = NULL; const char* const envval = getenv (envvar); - if (envval) + if (envval && strlen (envval)) full_path = combinePathAndFile(envval, path); return full_path; @@ -3544,9 +3544,11 @@ static char *getConfigAtHomeOnWindows (const char *path, vStringCatS (windowsHome, homeDrive); vStringCatS (windowsHome, homePath); - char *tmp = combinePathAndFile (vStringValue(windowsHome), path); - vStringDelete (windowsHome); + char *tmp = vStringIsEmpty (windowsHome) + ? NULL + : combinePathAndFile (vStringValue(windowsHome), path); + vStringDelete (windowsHome); return tmp; } return NULL; diff --git a/main/routines.c b/main/routines.c index f9e64a55ff..d4d726bd27 100644 --- a/main/routines.c +++ b/main/routines.c @@ -714,14 +714,18 @@ extern char *combinePathAndFile ( const char *const path, const char *const file) { vString *const filePath = vStringNew (); - const int lastChar = path [strlen (path) - 1]; - bool terminated = isPathSeparator (lastChar); + size_t len = strlen (path); - vStringCopyS (filePath, path); - if (! terminated) - vStringPut (filePath, OUTPUT_PATH_SEPARATOR); - vStringCatS (filePath, file); + if (len) + { + const int lastChar = path [len - 1]; + bool terminated = isPathSeparator (lastChar); + vStringCopyS (filePath, path); + if (! terminated) + vStringPut (filePath, OUTPUT_PATH_SEPARATOR); + } + vStringCatS (filePath, file); return vStringDeleteUnwrap (filePath); }