From 4f2b9ad2e16ede43998b443766a1159f2e162b62 Mon Sep 17 00:00:00 2001 From: Karthik Gururaj Date: Tue, 3 May 2016 09:07:44 -0700 Subject: [PATCH] getenv() may return NULL if a variable isn't defined - this happens for batch job submissions. --- core/src/misc/utils.cc | 3 ++- core/src/storage_manager/storage_manager.cc | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/misc/utils.cc b/core/src/misc/utils.cc index f19a9330..63562c13 100644 --- a/core/src/misc/utils.cc +++ b/core/src/misc/utils.cc @@ -801,7 +801,8 @@ int read_from_file_with_mmap( std::string real_dir(const std::string& dir) { // Initialize current, home and root std::string current = current_dir(); - std::string home = getenv("HOME"); + auto env_home_ptr = getenv("HOME"); + std::string home = env_home_ptr ? env_home_ptr : current; std::string root = "/"; // Easy cases diff --git a/core/src/storage_manager/storage_manager.cc b/core/src/storage_manager/storage_manager.cc index d40b6f3a..e49507cc 100755 --- a/core/src/storage_manager/storage_manager.cc +++ b/core/src/storage_manager/storage_manager.cc @@ -106,7 +106,8 @@ int StorageManager::init(const char* config_filename) { // Set the TileDB home directory tiledb_home_ = TILEDB_HOME; if(tiledb_home_ == "") { - tiledb_home_ = getenv("HOME"); + auto env_home_ptr = getenv("HOME"); + tiledb_home_ = env_home_ptr ? env_home_ptr : ""; if(tiledb_home_ == "") { char cwd[1024]; if(getcwd(cwd, sizeof(cwd)) != NULL) {