summaryrefslogtreecommitdiffstats
path: root/Src
diff options
context:
space:
mode:
authorMikael Magnusson <mikachu@gmail.com>2026-05-12 16:55:00 +0200
committerMikael Magnusson <mikachu@gmail.com>2026-05-16 18:28:31 +0200
commit3fc8de8991b4bb28fad10b79d468c3a18094c77f (patch)
tree141b903db3b6d30971e1da891f274436ade5e634 /Src
parent54559: nearcolor was missing the third grayscale entry in 88 color mode (diff)
downloadzsh-3fc8de8991b4bb28fad10b79d468c3a18094c77f.tar
zsh-3fc8de8991b4bb28fad10b79d468c3a18094c77f.tar.gz
zsh-3fc8de8991b4bb28fad10b79d468c3a18094c77f.tar.bz2
zsh-3fc8de8991b4bb28fad10b79d468c3a18094c77f.tar.lz
zsh-3fc8de8991b4bb28fad10b79d468c3a18094c77f.tar.xz
zsh-3fc8de8991b4bb28fad10b79d468c3a18094c77f.tar.zst
zsh-3fc8de8991b4bb28fad10b79d468c3a18094c77f.zip
54560: parameter: Fix some issues in the parameter module
use strtol, not strtod use WEXITSTATUS on returned status, though I'm not sure when this path can actually be taken? don't abort getting group names just because one name is missing storing ${(kv)parameters} in a copy and then reading that wouldn't say what type a nameref pointed to setting multiple options via options=( foo on ) didn't verify the option name before trying to set it, reporting it as a failure to set it instead
Diffstat (limited to 'Src')
-rw-r--r--Src/Modules/parameter.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c
index 66483ad24..6d1f74d22 100644
--- a/Src/Modules/parameter.c
+++ b/Src/Modules/parameter.c
@@ -40,7 +40,7 @@ static int incleanup;
/**/
static char *
-paramtypestr(Param pm)
+paramtypestr(Param pm, int append)
{
char *val = NULL;
int f = pm->node.flags;
@@ -91,6 +91,13 @@ paramtypestr(Param pm)
} else
val = dupstring("");
+ if (append) {
+ if ((pm->node.flags & PM_NAMEREF) && pm->u.str && *(pm->u.str) &&
+ (pm = (Param) realparamtab->getnode(realparamtab, pm->node.nam)) &&
+ !(pm->node.flags & PM_UNSET)) {
+ val = zhtricat(val, "-", paramtypestr(pm, 0));
+ }
+ }
return val;
}
@@ -106,12 +113,7 @@ getpmparameter(UNUSED(HashTable ht), const char *name)
pm->gsu.s = &nullsetscalar_gsu;
if ((rpm = (Param) realparamtab->getnode2(realparamtab, name)) &&
!(rpm->node.flags & PM_UNSET)) {
- pm->u.str = paramtypestr(rpm);
- if ((rpm->node.flags & PM_NAMEREF) && rpm->u.str && *(rpm->u.str) &&
- (rpm = (Param) realparamtab->getnode(realparamtab, name)) &&
- !(rpm->node.flags & PM_UNSET)) {
- pm->u.str = zhtricat(pm->u.str, "-", paramtypestr(rpm));
- }
+ pm->u.str = paramtypestr(rpm, 1);
} else {
pm->u.str = dupstring("");
pm->node.flags |= (PM_UNSET|PM_SPECIAL);
@@ -139,7 +141,7 @@ scanpmparameters(UNUSED(HashTable ht), ScanFunc func, int flags)
if (func != scancountparams &&
((flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)) ||
!(flags & SCANPM_WANTKEYS)))
- pm.u.str = paramtypestr((Param) hn);
+ pm.u.str = paramtypestr((Param) hn, 1);
func(&pm.node, flags);
}
}
@@ -962,6 +964,7 @@ setpmoptions(Param pm, HashTable ht)
for (hn = ht->nodes[i]; hn; hn = hn->next) {
struct value v;
char *val;
+ int n;
v.scanflags = v.valflags = v.start = 0;
v.end = -1;
@@ -971,8 +974,9 @@ setpmoptions(Param pm, HashTable ht)
val = getstrvalue(&v);
if (!val || (strcmp(val, "on") && strcmp(val, "off")))
zwarn("invalid value: %s", val);
- else if (dosetopt(optlookup(hn->nam),
- (val && strcmp(val, "off")), 0, opts))
+ else if (!(n = optlookup(hn->nam)))
+ zwarn("no such option: %s", hn->nam);
+ else if (dosetopt(n, (val && strcmp(val, "off")), 0, opts))
zwarn("can't change option: %s", hn->nam);
}
/* See setpmcommands() above */
@@ -1288,7 +1292,7 @@ getpmjobtext(UNUSED(HashTable ht), const char *name)
selectjobtab(&jtab, &jmax);
- job = strtod(name, &pend);
+ job = strtol(name, &pend, 10);
/* Non-numeric keys are looked up by job name */
if (*pend)
job = getjob(name, NULL);
@@ -1362,7 +1366,8 @@ pmjobstate(Job jtab, int job)
state = "running";
else if (WIFEXITED(pn->status)) {
if (WEXITSTATUS(pn->status))
- sprintf((state = buf2), "exit %d", (pn->status));
+ sprintf((state = buf2), "exit %d",
+ WEXITSTATUS(pn->status));
else
state = "done";
} else if (WIFSTOPPED(pn->status))
@@ -1396,7 +1401,7 @@ getpmjobstate(UNUSED(HashTable ht), const char *name)
selectjobtab(&jtab, &jmax);
- job = strtod(name, &pend);
+ job = strtol(name, &pend, 10);
if (*pend)
job = getjob(name, NULL);
if (job >= 1 && job <= jmax &&
@@ -1468,7 +1473,7 @@ getpmjobdir(UNUSED(HashTable ht), const char *name)
selectjobtab(&jtab, &jmax);
- job = strtod(name, &pend);
+ job = strtol(name, &pend, 10);
if (*pend)
job = getjob(name, NULL);
if (job >= 1 && job <= jmax &&
@@ -2086,9 +2091,12 @@ static Groupset get_all_groups(void)
for (gaptr = gs->array; gaptr < gs->array + gs->num; gaptr++) {
grptr = getgrgid(gaptr->gid);
if (!grptr) {
- return NULL;
- }
- gaptr->name = dupstring(grptr->gr_name);
+ /* a group we're in has been deleted from /etc/groups */
+ char buf[DIGBUFSIZE];
+ convbase(buf, (zlong)gaptr->gid, 10);
+ gaptr->name = dupstring(buf);
+ } else
+ gaptr->name = dupstring(grptr->gr_name);
}
return gs;