Fix for Coverity CID#2: false bug, but still a problem.

Analysis:
internal_errorf(int, fmt, ...) was only a __dead function if the int argument
was non-0, which the Prevent probably was unable to follow. Change all uses of
internal_errorf(0, fmt, ...) to internal_warningf(fmt, ...); change the pro-
totype of internal_errorf() to internal_errorf(fmt, ...) and all remaining
uses remove the non-0 int argument; add __dead to internal_errorf() proto;
flesh out guts of internal_errorf() and internal_warningf() into a new local
function for optimisation purposes.

Some whitespace cleanup and dead code removal (return after internal_errorf(1))
This commit is contained in:
tg
2007-05-13 17:51:24 +00:00
parent d2d035355f
commit 0989f7da67
13 changed files with 91 additions and 74 deletions

38
shf.c
View File

@@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.13 2007/03/10 18:16:28 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.14 2007/05/13 17:51:23 tg Exp $");
/* flags to shf_emptybuf() */
#define EB_READSW 0x01 /* about to switch to reading */
@@ -88,7 +88,7 @@ shf_fdopen(int fd, int sflags, struct shf *shf)
}
if (!(sflags & (SHF_RD | SHF_WR)))
internal_errorf(1, "shf_fdopen: missing read/write");
internal_errorf("shf_fdopen: missing read/write");
if (shf) {
if (bsize) {
@@ -145,9 +145,9 @@ shf_reopen(int fd, int sflags, struct shf *shf)
}
if (!(sflags & (SHF_RD | SHF_WR)))
internal_errorf(1, "shf_reopen: missing read/write");
internal_errorf("shf_reopen: missing read/write");
if (!shf || !shf->buf || shf->bsize < bsize)
internal_errorf(1, "shf_reopen: bad shf/buf/bsize");
internal_errorf("shf_reopen: bad shf/buf/bsize");
/* assumes shf->buf and shf->bsize already set up */
shf->fd = fd;
@@ -177,7 +177,7 @@ shf_sopen(char *buf, int bsize, int sflags, struct shf *shf)
/* can't have a read+write string */
if (!(sflags & (SHF_RD | SHF_WR)) ||
(sflags & (SHF_RD | SHF_WR)) == (SHF_RD | SHF_WR))
internal_errorf(1, "shf_sopen: flags 0x%x", sflags);
internal_errorf("shf_sopen: flags 0x%x", sflags);
if (!shf) {
shf = (struct shf *) alloc(sizeof(struct shf), ATEMP);
@@ -270,7 +270,7 @@ shf_flush(struct shf *shf)
return (shf->flags & SHF_WR) ? EOF : 0;
if (shf->fd < 0)
internal_errorf(1, "shf_flush: no fd");
internal_errorf("shf_flush: no fd");
if (shf->flags & SHF_ERROR) {
errno = shf->errno_;
@@ -300,7 +300,7 @@ shf_emptybuf(struct shf *shf, int flags)
int ret = 0;
if (!(shf->flags & SHF_STRING) && shf->fd < 0)
internal_errorf(1, "shf_emptybuf: no fd");
internal_errorf("shf_emptybuf: no fd");
if (shf->flags & SHF_ERROR) {
errno = shf->errno_;
@@ -381,7 +381,7 @@ shf_fillbuf(struct shf *shf)
return 0;
if (shf->fd < 0)
internal_errorf(1, "shf_fillbuf: no fd");
internal_errorf("shf_fillbuf: no fd");
if (shf->flags & (SHF_EOF | SHF_ERROR)) {
if (shf->flags & SHF_ERROR)
@@ -427,10 +427,10 @@ shf_read(char *buf, int bsize, struct shf *shf)
int ncopy;
if (!(shf->flags & SHF_RD))
internal_errorf(1, "shf_read: flags %x", shf->flags);
internal_errorf("shf_read: flags %x", shf->flags);
if (bsize <= 0)
internal_errorf(1, "shf_read: bsize %d", bsize);
internal_errorf("shf_read: bsize %d", bsize);
while (bsize > 0) {
if (shf->rnleft == 0 &&
@@ -462,7 +462,7 @@ shf_getse(char *buf, int bsize, struct shf *shf)
char *orig_buf = buf;
if (!(shf->flags & SHF_RD))
internal_errorf(1, "shf_getse: flags %x", shf->flags);
internal_errorf("shf_getse: flags %x", shf->flags);
if (bsize <= 0)
return NULL;
@@ -497,7 +497,7 @@ int
shf_getchar(struct shf *shf)
{
if (!(shf->flags & SHF_RD))
internal_errorf(1, "shf_getchar: flags %x", shf->flags);
internal_errorf("shf_getchar: flags %x", shf->flags);
if (shf->rnleft == 0 && (shf_fillbuf(shf) == EOF || shf->rnleft == 0))
return EOF;
@@ -512,7 +512,7 @@ int
shf_ungetc(int c, struct shf *shf)
{
if (!(shf->flags & SHF_RD))
internal_errorf(1, "shf_ungetc: flags %x", shf->flags);
internal_errorf("shf_ungetc: flags %x", shf->flags);
if ((shf->flags & SHF_ERROR) || c == EOF ||
(shf->rp == shf->buf && shf->rnleft))
@@ -547,7 +547,7 @@ int
shf_putchar(int c, struct shf *shf)
{
if (!(shf->flags & SHF_WR))
internal_errorf(1, "shf_putchar: flags %x", shf->flags);
internal_errorf("shf_putchar: flags %x", shf->flags);
if (c == EOF)
return EOF;
@@ -557,7 +557,7 @@ shf_putchar(int c, struct shf *shf)
int n;
if (shf->fd < 0)
internal_errorf(1, "shf_putchar: no fd");
internal_errorf("shf_putchar: no fd");
if (shf->flags & SHF_ERROR) {
errno = shf->errno_;
return EOF;
@@ -603,10 +603,10 @@ shf_write(const char *buf, int nbytes, struct shf *shf)
int ncopy;
if (!(shf->flags & SHF_WR))
internal_errorf(1, "shf_write: flags %x", shf->flags);
internal_errorf("shf_write: flags %x", shf->flags);
if (nbytes < 0)
internal_errorf(1, "shf_write: nbytes %d", nbytes);
internal_errorf("shf_write: nbytes %d", nbytes);
/* Don't buffer if buffer is empty and we're writting a large amount. */
if ((ncopy = shf->wnleft) &&
@@ -676,8 +676,8 @@ shf_snprintf(char *buf, int bsize, const char *fmt, ...)
int n;
if (!buf || bsize <= 0)
internal_errorf(1, "shf_snprintf: buf %lx, bsize %d",
(long) buf, bsize);
internal_errorf("shf_snprintf: buf %lx, bsize %d",
(long)buf, bsize);
shf_sopen(buf, bsize, SHF_WR, &shf);
va_start(args, fmt);