diff --git a/libbb/lineedit.c b/libbb/lineedit.c index a018a53ff..a66398a95 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -81,8 +81,9 @@ static int num_ok_lines = 1; #endif #if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR -static char *user_buf = (char*)""; -static char *home_pwd_buf = (char*)""; +static const char null_str[] = ""; +static char *user_buf; +static char *home_pwd_buf = (char*)null_str; #endif /* Put 'command_ps[cursor]', cursor++. @@ -311,7 +312,7 @@ static void username_tab_completion(char *ud, char *with_shash_flg) if (with_shash_flg) { /* "~/..." or "~user/..." */ char *sav_ud = ud - 1; - char *home = 0; + char *home = NULL; char *temp; if (*ud == '/') { /* "~/..." */ @@ -1119,7 +1120,7 @@ static void parse_prompt(const char *prmt_ptr) switch (c) { #if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR case 'u': - pbuf = user_buf; + pbuf = user_buf ? user_buf : (char*)""; break; #endif case 'h': @@ -1143,7 +1144,7 @@ static void parse_prompt(const char *prmt_ptr) case 'w': pbuf = pwd_buf; l = strlen(home_pwd_buf); - if (home_pwd_buf[0] != 0 + if (l != 0 && strncmp(home_pwd_buf, pbuf, l) == 0 && (pbuf[l]=='/' || pbuf[l]=='\0') && strlen(pwd_buf+l)pw_name); home_pwd_buf = xstrdup(entry->pw_dir); + /* They are not freed on exit (too small to bother) */ } } #endif