(very few) fixes and a couple of workarounds for Coverity

This commit is contained in:
tg 2017-04-12 16:46:23 +00:00
parent efe13f6942
commit 30cae62468
5 changed files with 32 additions and 28 deletions

9
edit.c
View File

@ -28,7 +28,7 @@
#ifndef MKSH_NO_CMDLINE_EDITING
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.320 2017/04/12 15:54:47 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.321 2017/04/12 16:46:20 tg Exp $");
/*
* in later versions we might use libtermcap for this, but since external
@ -1786,12 +1786,11 @@ x_newline(int c MKSH_A_UNUSED)
static int
x_end_of_text(int c MKSH_A_UNUSED)
{
unsigned char tmp;
char *cp = (void *)&tmp;
unsigned char tmp[1], *cp = tmp;
tmp = isedchar(edchars.eof) ? (unsigned char)edchars.eof :
*tmp = isedchar(edchars.eof) ? (unsigned char)edchars.eof :
(unsigned char)CTRL('D');
x_zotc3(&cp);
x_zotc3((char **)&cp);
x_putc('\r');
x_putc('\n');
x_flush();

10
exec.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.195 2017/04/08 01:07:15 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.196 2017/04/12 16:46:21 tg Exp $");
#ifndef MKSH_DEFAULT_EXECSHELL
#define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh"
@ -376,9 +376,8 @@ execute(struct op * volatile t,
if (t->right == NULL)
/* should be error */
break;
rv = execute(t->left, XERROK, NULL) == 0 ?
execute(t->right->left, flags & XERROK, xerrok) :
execute(t->right->right, flags & XERROK, xerrok);
rv = execute(execute(t->left, XERROK, NULL) == 0 ?
t->right->left : t->right->right, flags & XERROK, xerrok);
break;
case TCASE:
@ -1507,7 +1506,10 @@ iosetup(struct ioword *iop, struct tbl *tp)
if (u == -1) {
u = errno;
warningf(true, Tf_cant_ss_s,
#if 0
/* can't happen */
iotype == IODUP ? "dup" :
#endif
(iotype == IOREAD || iotype == IOHERE) ?
Topen : Tcreate, cp, cstrerror(u));
}

4
misc.c
View File

@ -30,7 +30,7 @@
#include <grp.h>
#endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.254 2017/04/02 13:08:06 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.255 2017/04/12 16:46:22 tg Exp $");
#define KSH_CHVT_FLAG
#ifdef MKSH_SMALL
@ -501,7 +501,7 @@ parse_args(const char **argv,
if (arrayset) {
const char *ccp = NULL;
if (*array)
if (array && *array)
ccp = skip_varname(array, false);
if (!ccp || !(!ccp[0] || (ccp[0] == '+' && !ccp[1]))) {
bi_errorf(Tf_sD_s, array, Tnot_ident);

33
shf.c
View File

@ -2,7 +2,7 @@
/*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011,
* 2012, 2013, 2015, 2016
* 2012, 2013, 2015, 2016, 2017
* mirabilos <m@mirbsd.org>
*
* Provided that these terms and disclaimer and all copyright notices
@ -25,7 +25,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.77 2017/04/02 15:00:45 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.78 2017/04/12 16:46:22 tg Exp $");
/* flags to shf_emptybuf() */
#define EB_READSW 0x01 /* about to switch to reading */
@ -289,29 +289,32 @@ shf_sclose(struct shf *shf)
int
shf_flush(struct shf *shf)
{
int rv;
if (shf->flags & SHF_STRING)
return ((shf->flags & SHF_WR) ? -1 : 0);
if (shf->fd < 0)
rv = (shf->flags & SHF_WR) ? -1 : 0;
else if (shf->fd < 0)
internal_errorf(Tf_sD_s, "shf_flush", "no fd");
if (shf->flags & SHF_ERROR) {
else if (shf->flags & SHF_ERROR) {
errno = shf->errnosv;
return (-1);
}
if (shf->flags & SHF_READING) {
rv = -1;
} else if (shf->flags & SHF_READING) {
rv = 0;
shf->flags &= ~(SHF_EOF | SHF_READING);
if (shf->rnleft > 0) {
lseek(shf->fd, (off_t)-shf->rnleft, SEEK_CUR);
if (lseek(shf->fd, (off_t)-shf->rnleft,
SEEK_CUR) == -1) {
shf->flags |= SHF_ERROR;
shf->errnosv = errno;
rv = -1;
}
shf->rnleft = 0;
shf->rp = shf->buf;
}
return (0);
} else if (shf->flags & SHF_WRITING)
return (shf_emptybuf(shf, 0));
rv = shf_emptybuf(shf, 0);
return (0);
return (rv);
}
/*

4
tree.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.88 2017/04/11 12:34:04 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.89 2017/04/12 16:46:23 tg Exp $");
#define INDENT 8
@ -58,7 +58,7 @@ ptree(struct op *t, int indent, struct shf *shf)
case TCOM:
prevent_semicolon = false;
/* special-case 'var=<<EOF' (cf. exec.c:execute) */
if (
if (t->args &&
/* we have zero arguments, i.e. no program to run */
t->args[0] == NULL &&
/* we have exactly one variable assignment */