From 49daff2cedaf252a997dffe3c670513b51a0f2a3 Mon Sep 17 00:00:00 2001 From: Kevin Mooney Date: Fri, 19 Jan 2018 14:06:55 +0000 Subject: [PATCH] Fixed #373, segmentation fault when HOME is unset (#375) --- src/common.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/common.cc b/src/common.cc index 5f6310bd..b5cce1c5 100644 --- a/src/common.cc +++ b/src/common.cc @@ -130,11 +130,12 @@ double get_time(void) return tv.tv_sec + (tv.tv_nsec * 1e-9); } -/* Converts '~/...' paths to '/home/blah/...' - * It's similar to variable_substitute, except only cheques for $HOME and ~/ in path */ +/* Converts '~/...' paths to '/home/blah/...'. It's similar to + * variable_substitute, except only cheques for $HOME and ~/ in + * path. If HOME is unset it uses an empty string for substitution */ std::string to_real_path(const std::string &source) { - const char *homedir = getenv("HOME"); + const char *homedir = getenv("HOME") ? : ""; if(source.find("~/") == 0) return homedir + source.substr(1); else if(source.find("$HOME/") == 0)