diff options
author | Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp> | 2023-04-09 20:44:58 +0900 |
---|---|---|
committer | Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp> | 2023-04-09 20:44:58 +0900 |
commit | 8a9aea907ac4844e2ee7348c4fa6417ae9873991 (patch) | |
tree | 55eca9b97d1925990d78edcb333e83fc9489ec1b /Src/init.c | |
parent | 98b4d4bdca15393d3cce9e072867ee6526de5d2e (diff) | |
download | zsh-8a9aea907ac4844e2ee7348c4fa6417ae9873991.tar.gz zsh-8a9aea907ac4844e2ee7348c4fa6417ae9873991.tar.xz zsh-8a9aea907ac4844e2ee7348c4fa6417ae9873991.zip |
51631: initialize $_ by copying it from environment
Diffstat (limited to 'Src/init.c')
-rw-r--r-- | Src/init.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Src/init.c b/Src/init.c index 68621a0ad..7e98af44c 100644 --- a/Src/init.c +++ b/Src/init.c @@ -1084,9 +1084,12 @@ setupvals(char *cmd, char *runscript, char *zsh_name) ztrdup(DEFAULT_IFS_SH) : ztrdup(DEFAULT_IFS); wordchars = ztrdup(DEFAULT_WORDCHARS); postedit = ztrdup(""); - zunderscore = (char *) zalloc(underscorelen = 32); - underscoreused = 1; - *zunderscore = '\0'; + /* If _ is set in environment then initialize our $_ by copying it */ + zunderscore = getenv("_"); + zunderscore = zunderscore ? metafy(zunderscore, -1, META_DUP) : ztrdup(""); + underscoreused = strlen(zunderscore) + 1; + underscorelen = (underscoreused + 31) & ~31; + zunderscore = (char *)zrealloc(zunderscore, underscorelen); zoptarg = ztrdup(""); zoptind = 1; |