1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-09-21 19:31:50 +02:00

52244: Fix a batch of minor defects reported by Coverity.

Coverity defects 1547831, 1547826 (remove unused function), 1521551,
1500752, 1500747, 1401549, 1372423, 1270645, 1255799, 1255792, 1255789,
1255787, 1255782, 1255750
This commit is contained in:
Bart Schaefer 2023-10-26 08:27:18 -07:00
parent 0c15cc8712
commit 98a6892cb1
10 changed files with 38 additions and 37 deletions

View File

@ -1,3 +1,12 @@
2023-10-25 Bart Schaefer <schaefer@zsh.org>
* 52244: Src/Modules/zutil.c, Src/Zle/compcore.c,
Src/Zle/compresult.c, Src/builtin.c, Src/glob.c, Src/hist.c,
Src/input.c, Src/params.c, Src/utils.c: Coverity defects 1547831,
1547826 (remove unused function), 1521551, 1500752, 1500747,
1401549, 1372423, 1270645, 1255799, 1255792, 1255789, 1255787,
1255782, 1255750
2023-10-24 Matthew Martin <phy1729@gmail.com>
* github #103: Christian Heusel: Completion/Unix/Command/_zfs: fix

View File

@ -1378,11 +1378,11 @@ rmatch(RParseResult *sm, char *subj, char *var1, char *var2, int comp)
"zregexparse-guard"), !lastval))) {
LinkNode aln;
char **mend;
int len;
int len = 0;
queue_signals();
mend = getaparam("mend");
len = atoi(mend[0]);
if ((mend = getaparam("mend")))
len = atoi(mend[0]);
unqueue_signals();
for (i = len; i; i--)

View File

@ -2249,8 +2249,9 @@ addmatches(Cadata dat, char **argv)
llpl = strlen(lpre);
llsl = strlen(lsuf);
if (llpl + (int)strlen(compqiprefix) + (int)strlen(lipre) != origlpre
|| llsl + (int)strlen(compqisuffix) + (int)strlen(lisuf) != origlsuf)
/* This used to reference compqiprefix and compqisuffix, why? */
if (llpl + (int)strlen(qipre) + (int)strlen(lipre) != origlpre
|| llsl + (int)strlen(qisuf) + (int)strlen(lisuf) != origlsuf)
lenchanged = 1;
/* Test if there is an existing -P prefix. */

View File

@ -897,7 +897,7 @@ void
do_allmatches(UNUSED(int end))
{
int first = 1, nm = nmatches - 1, omc = menucmp, oma = menuacc, e;
Cmatch *mc;
Cmatch *mc = 0;
struct menuinfo mi;
char *p = (brbeg ? ztrdup(lastbrbeg->str) : NULL);
@ -915,10 +915,10 @@ do_allmatches(UNUSED(int end))
#endif
}
if (minfo.group)
mc = (minfo.group)->matches;
mc = (minfo.group)->matches;
while (1) {
while (mc) {
if (!((*mc)->flags & CMF_ALL)) {
if (!first)
accept_last();
@ -1731,8 +1731,6 @@ calclist(int showall)
width < zterm_columns && nth < g->dcount;
nth++, tcol++) {
m = *p;
if (tcol == tcols) {
tcol = 0;
tlines++;
@ -1994,7 +1992,6 @@ printlist(int over, CLPrintFunc printm, int showall)
(listdat.onlyexpl & ((*e)->always > 0 ? 2 : 1)))) {
if (pnl) {
putc('\n', shout);
pnl = 0;
ml++;
if (cl >= 0 && --cl <= 1) {
cl = -1;
@ -2087,7 +2084,6 @@ printlist(int over, CLPrintFunc printm, int showall)
(showall || !(m->flags & (CMF_HIDE|CMF_NOLIST)))) {
if (pnl) {
putc('\n', shout);
pnl = 0;
ml++;
if (cl >= 0 && --cl <= 1) {
cl = -1;

View File

@ -6508,6 +6508,7 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
if (OPT_ISSET(ops,'s') && SHTTY == readfd) {
struct ttyinfo ti;
memset(&ti, 0, sizeof(struct ttyinfo));
gettyinfo(&ti);
saveti = ti;
resettty = 1;
@ -6606,7 +6607,8 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
else if (resettty && SHTTY != -1)
settyinfo(&saveti);
if (haso) {
fclose(shout);
if (shout)
fclose(shout);
shout = oshout;
SHTTY = -1;
}

View File

@ -1317,7 +1317,8 @@ zglob(LinkList list, LinkNode np, int nountok)
sense = 0;
if (qualct) {
qn = (struct qual *)hcalloc(sizeof *qn);
qo->or = qn;
if (qo)
qo->or = qn;
qo = qn;
qualorct++;
qualct = 0;

View File

@ -1359,7 +1359,8 @@ putoldhistentryontop(short keep_going)
do {
if (max_unique_ct-- <= 0 || he == hist_ring) {
max_unique_ct = 0;
he = hist_ring->down;
if (hist_ring)
he = hist_ring->down;
next = hist_ring;
break;
}
@ -1367,12 +1368,16 @@ putoldhistentryontop(short keep_going)
next = he->down;
} while (!(he->node.flags & HIST_DUP));
}
if (he != hist_ring->down) {
/* Is it really possible for hist_ring to be NULL here? */
if (he && (!hist_ring || he != hist_ring->down)) {
he->up->down = he->down;
he->down->up = he->up;
he->up = hist_ring;
he->down = hist_ring->down;
hist_ring->down = he->down->up = he;
if (hist_ring) {
he->down = hist_ring->down;
hist_ring->down = he;
}
he->down->up = he;
}
hist_ring = he;
}
@ -1468,7 +1473,7 @@ should_ignore_line(Eprog prog)
mod_export int
hend(Eprog prog)
{
int flag, hookret, stack_pos = histsave_stack_pos;
int flag, hookret = 0, stack_pos = histsave_stack_pos;
/*
* save:
* 0: don't save

View File

@ -643,18 +643,6 @@ zstuff(char **out, const char *fn)
return len;
}
/**/
char *
ztuff(const char *fn)
{
char *buf;
off_t len = zstuff(&buf, fn);
if (len > 0)
return buf;
else
return NULL;
}
/* stuff a whole file into the input queue and print it */
/**/

View File

@ -6326,10 +6326,9 @@ mod_export Param
upscope(Param pm, int reflevel)
{
Param up = pm->old;
while (pm && up && up->level >= reflevel) {
while (up && up->level >= reflevel) {
pm = up;
if (up)
up = up->old;
up = up->old;
}
return pm;
}

View File

@ -7523,8 +7523,8 @@ restoredir(struct dirsav *d)
else if (d->level < 0)
err = -1;
if (d->dev || d->ino) {
stat(".", &sbuf);
if (sbuf.st_ino != d->ino || sbuf.st_dev != d->dev)
if (stat(".", &sbuf) < 0 ||
sbuf.st_ino != d->ino || sbuf.st_dev != d->dev)
err = -2;
}
return err;