1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-06-10 18:58:03 +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> 2023-10-24 Matthew Martin <phy1729@gmail.com>
* github #103: Christian Heusel: Completion/Unix/Command/_zfs: fix * 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))) { "zregexparse-guard"), !lastval))) {
LinkNode aln; LinkNode aln;
char **mend; char **mend;
int len; int len = 0;
queue_signals(); queue_signals();
mend = getaparam("mend"); if ((mend = getaparam("mend")))
len = atoi(mend[0]); len = atoi(mend[0]);
unqueue_signals(); unqueue_signals();
for (i = len; i; i--) for (i = len; i; i--)

View file

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

View file

@ -897,7 +897,7 @@ void
do_allmatches(UNUSED(int end)) do_allmatches(UNUSED(int end))
{ {
int first = 1, nm = nmatches - 1, omc = menucmp, oma = menuacc, e; int first = 1, nm = nmatches - 1, omc = menucmp, oma = menuacc, e;
Cmatch *mc; Cmatch *mc = 0;
struct menuinfo mi; struct menuinfo mi;
char *p = (brbeg ? ztrdup(lastbrbeg->str) : NULL); char *p = (brbeg ? ztrdup(lastbrbeg->str) : NULL);
@ -915,10 +915,10 @@ do_allmatches(UNUSED(int end))
#endif #endif
} }
if (minfo.group)
mc = (minfo.group)->matches;
mc = (minfo.group)->matches; while (mc) {
while (1) {
if (!((*mc)->flags & CMF_ALL)) { if (!((*mc)->flags & CMF_ALL)) {
if (!first) if (!first)
accept_last(); accept_last();
@ -1731,8 +1731,6 @@ calclist(int showall)
width < zterm_columns && nth < g->dcount; width < zterm_columns && nth < g->dcount;
nth++, tcol++) { nth++, tcol++) {
m = *p;
if (tcol == tcols) { if (tcol == tcols) {
tcol = 0; tcol = 0;
tlines++; tlines++;
@ -1994,7 +1992,6 @@ printlist(int over, CLPrintFunc printm, int showall)
(listdat.onlyexpl & ((*e)->always > 0 ? 2 : 1)))) { (listdat.onlyexpl & ((*e)->always > 0 ? 2 : 1)))) {
if (pnl) { if (pnl) {
putc('\n', shout); putc('\n', shout);
pnl = 0;
ml++; ml++;
if (cl >= 0 && --cl <= 1) { if (cl >= 0 && --cl <= 1) {
cl = -1; cl = -1;
@ -2087,7 +2084,6 @@ printlist(int over, CLPrintFunc printm, int showall)
(showall || !(m->flags & (CMF_HIDE|CMF_NOLIST)))) { (showall || !(m->flags & (CMF_HIDE|CMF_NOLIST)))) {
if (pnl) { if (pnl) {
putc('\n', shout); putc('\n', shout);
pnl = 0;
ml++; ml++;
if (cl >= 0 && --cl <= 1) { if (cl >= 0 && --cl <= 1) {
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) { if (OPT_ISSET(ops,'s') && SHTTY == readfd) {
struct ttyinfo ti; struct ttyinfo ti;
memset(&ti, 0, sizeof(struct ttyinfo));
gettyinfo(&ti); gettyinfo(&ti);
saveti = ti; saveti = ti;
resettty = 1; resettty = 1;
@ -6606,7 +6607,8 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
else if (resettty && SHTTY != -1) else if (resettty && SHTTY != -1)
settyinfo(&saveti); settyinfo(&saveti);
if (haso) { if (haso) {
fclose(shout); if (shout)
fclose(shout);
shout = oshout; shout = oshout;
SHTTY = -1; SHTTY = -1;
} }

View file

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

View file

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

View file

@ -643,18 +643,6 @@ zstuff(char **out, const char *fn)
return len; 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 */ /* 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) upscope(Param pm, int reflevel)
{ {
Param up = pm->old; Param up = pm->old;
while (pm && up && up->level >= reflevel) { while (up && up->level >= reflevel) {
pm = up; pm = up;
if (up) up = up->old;
up = up->old;
} }
return pm; return pm;
} }

View file

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