-/* $OpenBSD: alloc.c,v 1.18 2017/11/02 06:55:35 tb Exp $ */
+/* $OpenBSD: alloc.c,v 1.19 2018/01/16 22:52:32 jca Exp $ */
/* Public domain, like most of the rest of ksh */
/* ensure that we don't overflow by allocating space for link */
if (size > SIZE_MAX - sizeof(struct link))
- internal_errorf(1, "unable to allocate memory");
+ internal_errorf("unable to allocate memory");
l = malloc(sizeof(struct link) + size);
if (l == NULL)
- internal_errorf(1, "unable to allocate memory");
+ internal_errorf("unable to allocate memory");
l->next = ap->freelist;
l->prev = NULL;
if (ap->freelist)
/* condition logic cloned from calloc() */
if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
nmemb > 0 && SIZE_MAX / nmemb < size) {
- internal_errorf(1, "unable to allocate memory");
+ internal_errorf("unable to allocate memory");
}
return aresize(ptr, nmemb * size, ap);
/* ensure that we don't overflow by allocating space for link */
if (size > SIZE_MAX - sizeof(struct link))
- internal_errorf(1, "unable to allocate memory");
+ internal_errorf("unable to allocate memory");
l = P2L(ptr);
lprev = l->prev;
l2 = realloc(l, sizeof(struct link) + size);
if (l2 == NULL)
- internal_errorf(1, "unable to allocate memory");
+ internal_errorf("unable to allocate memory");
if (lprev)
lprev->next = l2;
else
-/* $OpenBSD: c_ksh.c,v 1.57 2018/01/15 14:58:05 jca Exp $ */
+/* $OpenBSD: c_ksh.c,v 1.58 2018/01/16 22:52:32 jca Exp $ */
/*
* built-in Korn commands: c_*
}
if (genv->loc->next == NULL) {
- internal_errorf(0, "c_getopts: no argv");
+ internal_warningf("c_getopts: no argv");
return 1;
}
/* Which arguments are we parsing... */
-/* $OpenBSD: c_ulimit.c,v 1.25 2018/01/16 20:40:43 anton Exp $ */
+/* $OpenBSD: c_ulimit.c,v 1.26 2018/01/16 22:52:32 jca Exp $ */
/*
ulimit -- handle "ulimit" builtin
for (l = limits; l->name && l->option != optc; l++)
;
if (!l->name) {
- internal_errorf(0, "ulimit: %c", optc);
+ internal_warningf("ulimit: %c", optc);
return 1;
}
if (builtin_opt.optarg) {
-/* $OpenBSD: edit.c,v 1.62 2018/01/15 14:58:05 jca Exp $ */
+/* $OpenBSD: edit.c,v 1.63 2018/01/16 22:52:32 jca Exp $ */
/*
* Command line editing - common code
source = s;
if (yylex(ONEWORD|UNESCAPE) != LWORD) {
source = sold;
- internal_errorf(0, "fileglob: substitute error");
+ internal_warningf("fileglob: substitute error");
return 0;
}
source = sold;
/* Try to find the array. */
if (asprintf(&name, "complete_%.*s_%d", cmdlen, cmd, n) < 0)
- internal_errorf(1, "unable to allocate memory");
+ internal_errorf("unable to allocate memory");
v = global(name);
free(name);
if (~v->flag & (ISSET|ARRAY)) {
if (asprintf(&name, "complete_%.*s", cmdlen, cmd) < 0)
- internal_errorf(1, "unable to allocate memory");
+ internal_errorf("unable to allocate memory");
v = global(name);
free(name);
if (~v->flag & (ISSET|ARRAY))
-/* $OpenBSD: eval.c,v 1.58 2018/01/14 16:04:21 anton Exp $ */
+/* $OpenBSD: eval.c,v 1.59 2018/01/16 22:52:32 jca Exp $ */
/*
* Expansion - quoting, separation, substitution, globbing
s->start = s->str = cp;
source = s;
if (yylex(ONEWORD) != LWORD)
- internal_errorf(1, "substitute");
+ internal_errorf("substitute");
source = sold;
afree(s, ATEMP);
return evalstr(yylval.cp, f);
size_t len;
if (cp == NULL)
- internal_errorf(1, "expand(NULL)");
+ internal_errorf("expand(NULL)");
/* for alias, readonly, set, typeset commands */
if ((f & DOVACHECK) && is_wdvarassign(cp)) {
f &= ~(DOVACHECK|DOBLANK|DOGLOB|DOTILDE);
char *p;
if ((p = strdup("")) == NULL)
- internal_errorf(1, "unable "
+ internal_errorf("unable "
"to allocate memory");
XPput(*wp, p);
}
-/* $OpenBSD: exec.c,v 1.71 2018/01/15 14:58:05 jca Exp $ */
+/* $OpenBSD: exec.c,v 1.72 2018/01/16 22:52:32 jca Exp $ */
/*
* execute command tree
/* NOTREACHED */
default:
quitenv(NULL);
- internal_errorf(1, "CFUNC %d", i);
+ internal_errorf("CFUNC %d", i);
}
break;
}
tp = ktsearch(&builtins, *wp, hash(*wp));
if (tp == NULL)
- internal_errorf(1, "shcomexec: %s", *wp);
+ internal_errorf("shcomexec: %s", *wp);
return call_builtin(tp, wp);
}
s->start = s->str = content;
source = s;
if (yylex(ONEWORD|HEREDOC) != LWORD)
- internal_errorf(1, "herein: yylex");
+ internal_errorf("herein: yylex");
source = osource;
shf_puts(evalstr(yylval.cp, 0), shf);
} else
dbteste_error(Test_env *te, int offset, const char *msg)
{
te->flags |= TEF_ERROR;
- internal_errorf(0, "dbteste_error: %s (offset %d)", msg, offset);
+ internal_warningf("dbteste_error: %s (offset %d)", msg, offset);
}
-/* $OpenBSD: io.c,v 1.35 2016/03/20 00:01:21 krw Exp $ */
+/* $OpenBSD: io.c,v 1.36 2018/01/16 22:52:32 jca Exp $ */
/*
* shell buffered IO and formatted output
}
}
-/* Called when something that shouldn't happen does */
-void
-internal_errorf(int jump, const char *fmt, ...)
+static void
+internal_error_vwarn(const char *fmt, va_list va)
{
- va_list va;
-
error_prefix(true);
shf_fprintf(shl_out, "internal error: ");
- va_start(va, fmt);
shf_vfprintf(shl_out, fmt, va);
- va_end(va);
shf_putchar('\n', shl_out);
shf_flush(shl_out);
- if (jump)
- unwind(LERROR);
+}
+
+/* Warn when something that shouldn't happen does */
+void
+internal_warningf(const char *fmt, ...)
+{
+ va_list va;
+
+ va_start(va, fmt);
+ internal_error_vwarn(fmt, va);
+ va_end(va);
+}
+
+/* Warn and unwind when something that shouldn't happen does */
+__dead void
+internal_errorf(const char *fmt, ...)
+{
+ va_list va;
+
+ va_start(va, fmt);
+ internal_error_vwarn(fmt, va);
+ va_end(va);
+ unwind(LERROR);
}
/* used by error reporting functions to print "ksh: .kshrc[25]: " */
va_list va;
if (!shl_stdout_ok)
- internal_errorf(1, "shl_stdout not valid");
+ internal_errorf("shl_stdout not valid");
va_start(va, fmt);
shf_vfprintf(shl_stdout, fmt, va);
va_end(va);
-/* $OpenBSD: jobs.c,v 1.58 2018/01/08 22:22:28 benno Exp $ */
+/* $OpenBSD: jobs.c,v 1.59 2018/01/16 22:52:32 jca Exp $ */
/*
* Process and job control
/* link process into jobs list */
if (flags&XPIPEI) { /* continuing with a pipe */
if (!last_job)
- internal_errorf(1,
+ internal_errorf(
"exchild: XPIPEI and no last_job - pid %d",
(int) procpid);
j = last_job;
tty_close();
cleartraps();
execute(t, (flags & XERROK) | XEXEC, NULL); /* no return */
- internal_errorf(0, "exchild: execute() returned");
+ internal_warningf("exchild: execute() returned");
unwind(LLEAVE);
/* NOTREACHED */
}
if (!j)
warningf(true, "waitlast: no last job");
else
- internal_errorf(0, "waitlast: not started");
+ internal_warningf("waitlast: not started");
sigprocmask(SIG_SETMASK, &omask, NULL);
return 125; /* not so arbitrary, non-zero value */
}
if (async_job && (async_job->flags & (JF_KNOWN|JF_ZOMBIE)) == JF_ZOMBIE)
remove_job(async_job, "async");
if (!(j->flags & JF_STARTED)) {
- internal_errorf(0, "j_async: job not started");
+ internal_warningf("j_async: job not started");
return;
}
async_job = j;
if (!oldest) {
/* XXX debugging */
if (!(async_job->flags & JF_ZOMBIE) || nzombie != 1) {
- internal_errorf(0,
- "j_async: bad nzombie (%d)", nzombie);
+ internal_warningf("j_async: bad nzombie (%d)",
+ nzombie);
nzombie = 0;
}
break;
/* XXX debugging (nasty - interrupt routine using shl_out) */
if (!(j->flags & JF_STARTED)) {
- internal_errorf(0, "check_job: job started (flags 0x%x)",
+ internal_warningf("check_job: job started (flags 0x%x)",
j->flags);
return;
}
for (; curr != NULL && curr != j; prev = &curr->next, curr = *prev)
;
if (curr != j) {
- internal_errorf(0, "remove_job: job not found (%s)", where);
+ internal_warningf("remove_job: job not found (%s)", where);
return;
}
*prev = curr->next;
-/* $OpenBSD: main.c,v 1.88 2018/01/15 14:58:05 jca Exp $ */
+/* $OpenBSD: main.c,v 1.89 2018/01/16 22:52:32 jca Exp $ */
/*
* startup, main loop, environments and error handling
unwind(i);
/* NOTREACHED */
default:
- internal_errorf(1, "include: %d", i);
+ internal_errorf("include: %d", i);
/* NOTREACHED */
}
}
default:
source = old_source;
quitenv(NULL);
- internal_errorf(1, "shell: %d", i);
+ internal_errorf("shell: %d", i);
/* NOTREACHED */
}
}
-/* $OpenBSD: misc.c,v 1.67 2018/01/15 14:58:05 jca Exp $ */
+/* $OpenBSD: misc.c,v 1.68 2018/01/16 22:52:32 jca Exp $ */
/*
* Miscellaneous functions
break;
}
if (ele == NELEM(sh_options)) {
- internal_errorf(1, "parse_args: `%c'", optc);
+ internal_errorf("parse_args: `%c'", optc);
return -1; /* not reached */
}
}
-/* $OpenBSD: sh.h,v 1.70 2018/01/15 14:58:05 jca Exp $ */
+/* $OpenBSD: sh.h,v 1.71 2018/01/16 22:52:32 jca Exp $ */
/*
* Public Domain Bourne/Korn shell
__attribute__((__format__ (printf, 2, 3)));
void bi_errorf(const char *, ...)
__attribute__((__format__ (printf, 1, 2)));
-void internal_errorf(int, const char *, ...)
- __attribute__((__format__ (printf, 2, 3)));
+void internal_errorf(const char *, ...)
+ __attribute__((__noreturn__, __format__ (printf, 1, 2)));
+void internal_warningf(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
void error_prefix(int);
void shellf(const char *, ...)
__attribute__((__format__ (printf, 1, 2)));
-/* $OpenBSD: shf.c,v 1.31 2016/03/20 00:01:21 krw Exp $ */
+/* $OpenBSD: shf.c,v 1.32 2018/01/16 22:52:32 jca Exp $ */
/*
* Shell file I/O routines
}
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) {
}
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;
/* 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 = alloc(sizeof(struct shf), ATEMP);
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_;
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_;
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)
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 &&
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;
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;
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))
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;
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;
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) &&
int n;
if (!buf || bsize <= 0)
- internal_errorf(1, "shf_snprintf: buf %lx, bsize %d",
+ internal_errorf("shf_snprintf: buf %lx, bsize %d",
(long) buf, bsize);
shf_sopen(buf, bsize, SHF_WR, &shf);
-/* $OpenBSD: table.c,v 1.24 2017/12/27 13:02:57 millert Exp $ */
+/* $OpenBSD: table.c,v 1.25 2018/01/16 22:52:32 jca Exp $ */
/*
* dynamic hashed associative table for commands and variables
if (tp->size <= INT_MAX/2)
texpand(tp, 2*tp->size);
else
- internal_errorf(1, "too many vars");
+ internal_errorf("too many vars");
goto Search;
}
-/* $OpenBSD: trap.c,v 1.30 2016/03/17 23:33:23 mmcc Exp $ */
+/* $OpenBSD: trap.c,v 1.31 2018/01/16 22:52:32 jca Exp $ */
/*
* signal handling
{
/* XXX debugging */
if (!(p->flags & (TF_ORIG_IGN|TF_ORIG_DFL)))
- internal_errorf(1, "setexecsig: unset signal %d(%s)",
+ internal_errorf("setexecsig: unset signal %d(%s)",
p->signal, p->name);
/* restore original value for exec'd kids */
-/* $OpenBSD: tree.c,v 1.30 2018/01/06 16:28:58 millert Exp $ */
+/* $OpenBSD: tree.c,v 1.31 2018/01/16 22:52:32 jca Exp $ */
/*
* command tree climbing
nest--;
break;
default:
- internal_errorf(0,
+ internal_warningf(
"wdscan: unknown char 0x%x (carrying on)",
wp[-1]);
}
-/* $OpenBSD: var.c,v 1.64 2018/01/15 14:58:05 jca Exp $ */
+/* $OpenBSD: var.c,v 1.65 2018/01/16 22:52:32 jca Exp $ */
#include <sys/stat.h>
/* debugging */
if (s >= vq->val.s &&
s <= vq->val.s + strlen(vq->val.s))
- internal_errorf(true,
+ internal_errorf(
"setstr: %s=%s: assigning to self",
vq->name, s);
afree(vq->val.s, vq->areap);
-/* $OpenBSD: vi.c,v 1.54 2018/01/13 02:06:54 schwarze Exp $ */
+/* $OpenBSD: vi.c,v 1.55 2018/01/16 22:52:32 jca Exp $ */
/*
* vi command editing
}
(void) histnum(n);
if ((hptr = *histpos()) == NULL) {
- internal_errorf(0, "grabhist: bad history array");
+ internal_warningf("grabhist: bad history array");
return -1;
}
if (save)