Author: vangyzen Date: Wed May 11 22:13:50 2016 New Revision: 299488 URL: https://svnweb.freebsd.org/changeset/base/299488
Log: MFC r299035: sh: Handle empty hostname and $PWD when building prompt If the hostname is empty and \h is used in $PS1, the remainder of the prompt following \h will be empty. Likewise for $PWD and \w. Fix it. Modified: stable/9/bin/sh/parser.c Directory Properties: stable/9/bin/sh/ (props changed) Modified: stable/9/bin/sh/parser.c ============================================================================== --- stable/9/bin/sh/parser.c Wed May 11 22:11:37 2016 (r299487) +++ stable/9/bin/sh/parser.c Wed May 11 22:13:50 2016 (r299488) @@ -1982,8 +1982,9 @@ getprompt(void *unused __unused) gethostname(&ps[i], PROMPTLEN - i); /* Skip to end of hostname. */ trim = (*fmt == 'h') ? '.' : '\0'; - while ((ps[i+1] != '\0') && (ps[i+1] != trim)) + while ((ps[i] != '\0') && (ps[i] != trim)) i++; + --i; break; /* @@ -1995,7 +1996,7 @@ getprompt(void *unused __unused) case 'W': case 'w': pwd = lookupvar("PWD"); - if (pwd == NULL) + if (pwd == NULL || *pwd == '\0') pwd = "?"; if (*fmt == 'W' && *pwd == '/' && pwd[1] != '\0') _______________________________________________ svn-src-stable-9@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-stable-9 To unsubscribe, send any mail to "svn-src-stable-9-unsubscr...@freebsd.org"