diff --git a/parse_util.cpp b/parse_util.cpp index 971e258b5..9a3e217f8 100644 --- a/parse_util.cpp +++ b/parse_util.cpp @@ -800,7 +800,7 @@ int parse_util_load( const wcstring &cmd, void (*on_load)(const wchar_t *cmd), int reload ) { - wchar_t *path_var; + wcstring path_var; int res; int c, c2; @@ -811,12 +811,12 @@ int parse_util_load( const wcstring &cmd, // debug( 0, L"Autoload %ls in %ls", cmd, path_var_name ); parse_util_autounload( path_var_name.c_str(), cmd.c_str(), on_load ); - path_var = env_get( path_var_name.c_str() ); + path_var = env_get_string( path_var_name.c_str() ); /* Do we know where to look? */ - if( !path_var ) + if( path_var.empty() ) { return 0; } @@ -856,9 +856,9 @@ int parse_util_load( const wcstring &cmd, We have never tried to autoload using this path name before, set up initial data */ -// debug( 0, L"Create brand new autoload_t for %ls->%ls", path_var_name, path_var ); +// debug( 0, L"Create brand new autoload_t for %ls->%ls", path_var_name, path_var.c_str() ); loaded = &all_loaded_map[path_var_name]; - loaded->old_path = path_var; + loaded->old_path = wcsdup(path_var.c_str()); } std::vector path_list; diff --git a/parser.cpp b/parser.cpp index ed9cab0e7..ed2e7cd56 100644 --- a/parser.cpp +++ b/parser.cpp @@ -2043,7 +2043,9 @@ static int parse_job( process_t *p, } else if(cmd[0]==L'$') { - wchar_t *val = env_get( cmd+1 ); + + const wcstring val_wstr = env_get_string( cmd+1 ); + const wchar_t *val = val_wstr.empty()?NULL:val_wstr.c_str(); if( val ) { debug( 0, diff --git a/path.cpp b/path.cpp index 00f747c2c..2171720ec 100644 --- a/path.cpp +++ b/path.cpp @@ -130,7 +130,7 @@ bool path_get_path_string(const wcstring &cmd_str, wcstring &output, const env_v wchar_t *path_get_path( void *context, const wchar_t *cmd ) { - wchar_t *path; + const wchar_t *path; int err = ENOENT; @@ -166,7 +166,8 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd ) } else { - path = env_get(L"PATH"); + const wcstring path_wstr = env_get_string(L"PATH"); + path = path_wstr.empty()?NULL:path_wstr.c_str(); if( path == 0 ) { if( contains( PREFIX L"/bin", L"/bin", L"/usr/bin" ) ) @@ -189,7 +190,7 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd ) its arguments */ wchar_t *path_cpy = wcsdup( path ); - wchar_t *nxt_path = path; + const wchar_t *nxt_path = path; wchar_t *state; if( (new_cmd==0) || (path_cpy==0) ) @@ -356,20 +357,21 @@ wchar_t *path_get_cdpath( void *context, const wchar_t *dir ) } else { - wchar_t *path; + const wchar_t *path; wchar_t *path_cpy; wchar_t *nxt_path; wchar_t *state; wchar_t *whole_path; - path = env_get(L"CDPATH"); + const wcstring path_wstr = env_get_string(L"CDPATH"); + path = path_wstr.empty()?NULL:path_wstr.c_str(); if( !path || !wcslen(path) ) { path = L"."; } - nxt_path = path; + nxt_path = const_cast(path); path_cpy = wcsdup( path ); if( !path_cpy ) @@ -437,11 +439,12 @@ wchar_t *path_get_cdpath( void *context, const wchar_t *dir ) wchar_t *path_get_config( void *context) { - wchar_t *xdg_dir, *home; + const wchar_t *xdg_dir, *home; int done = 0; wchar_t *res = 0; - xdg_dir = env_get( L"XDG_CONFIG_HOME" ); + const wcstring xdg_dir_wstr = env_get_string( L"XDG_CONFIG_HOME" ); + xdg_dir = xdg_dir_wstr.empty()?NULL:xdg_dir_wstr.c_str(); if( xdg_dir ) { res = wcsdupcat( xdg_dir, L"/fish" ); @@ -457,7 +460,8 @@ wchar_t *path_get_config( void *context) } else { - home = env_get( L"HOME" ); + const wcstring home_wstr = env_get_string( L"HOME" ); + home = home_wstr.empty()?NULL:home_wstr.c_str(); if( home ) { res = wcsdupcat( home, L"/.config/fish" );