aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2022-02-27 20:39:54 +0200
committerArnold D. Robbins <arnold@skeeve.com>2022-02-27 20:39:54 +0200
commitfc1410099d6ccbb72adb54ecffd0711348706ca4 (patch)
treed04175556415fff6bcf66f48fc05c4da5f2d4908
parent7acb038bd54f81fb95dac70954e5c1b8ec07a086 (diff)
downloadegawk-fc1410099d6ccbb72adb54ecffd0711348706ca4.tar.gz
egawk-fc1410099d6ccbb72adb54ecffd0711348706ca4.tar.bz2
egawk-fc1410099d6ccbb72adb54ecffd0711348706ca4.zip
Have cant_happen() give more information.
-rw-r--r--ChangeLog8
-rw-r--r--awk.h4
-rw-r--r--awkgram.c10
-rw-r--r--awkgram.y10
-rw-r--r--debug.c2
-rw-r--r--eval.c4
-rw-r--r--interpret.h6
-rw-r--r--io.c6
-rw-r--r--main.c2
-rw-r--r--mpfr.c6
-rw-r--r--profile.c7
-rw-r--r--re.c2
-rw-r--r--symbol.c4
13 files changed, 39 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index f20dd21f..96a80815 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2022-02-27 Arnold D. Robbins <arnold@skeeve.com>
+
+ * awk.h (cant_happen): Change to allow a format string and arguments,
+ in order to provide a clue as to what went wrong, and not just
+ print "internal error".
+ * awkgram.y, debug.c, eval.c, interpret.h, io.c, main.c, mpfr.c,
+ profile.c, re.c, symbol.c: Fix all uses of cant_happen().
+
2022-02-22 Arnold D. Robbins <arnold@skeeve.com>
Fix resource links found by Coverity. Thanks to
diff --git a/awk.h b/awk.h
index 09c929c2..ca648087 100644
--- a/awk.h
+++ b/awk.h
@@ -1376,8 +1376,8 @@ extern void r_freeblock(void *, int id);
#define ALREADY_MALLOCED 2
#define ELIDE_BACK_NL 4
-#define cant_happen() r_fatal("internal error line %d, file: %s", \
- __LINE__, __FILE__)
+#define cant_happen(format, ...) r_fatal("internal error: file %s, line %d: " format, \
+ __FILE__, __LINE__, __VA_ARGS__)
#define emalloc(var,ty,x,str) (void) (var = (ty) emalloc_real((size_t)(x), str, #var, __FILE__, __LINE__))
#define ezalloc(var,ty,x,str) (void) (var = (ty) ezalloc_real((size_t)(x), str, #var, __FILE__, __LINE__))
diff --git a/awkgram.c b/awkgram.c
index 6ad01d6c..194b49e5 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -6912,7 +6912,7 @@ retry:
/* regular code */
break;
default:
- cant_happen();
+ cant_happen("bad value %d for want_param_names", (int) want_param_names);
break;
}
}
@@ -8871,7 +8871,7 @@ list_append(INSTRUCTION *l, INSTRUCTION *x)
{
#ifdef GAWKDEBUG
if (l->opcode != Op_list)
- cant_happen();
+ cant_happen("unexpected value %s for opcode", opcode2str(l->opcode));
#endif
l->lasti->nexti = x;
l->lasti = x;
@@ -8883,7 +8883,7 @@ list_prepend(INSTRUCTION *l, INSTRUCTION *x)
{
#ifdef GAWKDEBUG
if (l->opcode != Op_list)
- cant_happen();
+ cant_happen("unexpected value %s for opcode", opcode2str(l->opcode));
#endif
x->nexti = l->nexti;
l->nexti = x;
@@ -8895,9 +8895,9 @@ list_merge(INSTRUCTION *l1, INSTRUCTION *l2)
{
#ifdef GAWKDEBUG
if (l1->opcode != Op_list)
- cant_happen();
+ cant_happen("unexpected value %s for opcode", opcode2str(l1->opcode));
if (l2->opcode != Op_list)
- cant_happen();
+ cant_happen("unexpected value %s for opcode", opcode2str(l2->opcode));
#endif
l1->lasti->nexti = l2->nexti;
l1->lasti = l2->lasti;
diff --git a/awkgram.y b/awkgram.y
index 2ec91545..072d8adf 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -4404,7 +4404,7 @@ retry:
/* regular code */
break;
default:
- cant_happen();
+ cant_happen("bad value %d for want_param_names", (int) want_param_names);
break;
}
}
@@ -6363,7 +6363,7 @@ list_append(INSTRUCTION *l, INSTRUCTION *x)
{
#ifdef GAWKDEBUG
if (l->opcode != Op_list)
- cant_happen();
+ cant_happen("unexpected value %s for opcode", opcode2str(l->opcode));
#endif
l->lasti->nexti = x;
l->lasti = x;
@@ -6375,7 +6375,7 @@ list_prepend(INSTRUCTION *l, INSTRUCTION *x)
{
#ifdef GAWKDEBUG
if (l->opcode != Op_list)
- cant_happen();
+ cant_happen("unexpected value %s for opcode", opcode2str(l->opcode));
#endif
x->nexti = l->nexti;
l->nexti = x;
@@ -6387,9 +6387,9 @@ list_merge(INSTRUCTION *l1, INSTRUCTION *l2)
{
#ifdef GAWKDEBUG
if (l1->opcode != Op_list)
- cant_happen();
+ cant_happen("unexpected value %s for opcode", opcode2str(l1->opcode));
if (l2->opcode != Op_list)
- cant_happen();
+ cant_happen("unexpected value %s for opcode", opcode2str(l2->opcode));
#endif
l1->lasti->nexti = l2->nexti;
l1->lasti = l2->lasti;
diff --git a/debug.c b/debug.c
index e7dd7060..2849a4c1 100644
--- a/debug.c
+++ b/debug.c
@@ -1732,7 +1732,7 @@ watchpoint_triggered(struct list_item *w)
case Node_var_new:
break;
default:
- cant_happen();
+ cant_happen("unexpected symbol type %s", nodetype2str(symbol->type));
}
}
diff --git a/eval.c b/eval.c
index 9e644523..013ee062 100644
--- a/eval.c
+++ b/eval.c
@@ -1172,7 +1172,7 @@ r_get_lhs(NODE *n, bool reference)
break;
default:
- cant_happen();
+ cant_happen("unexpected variable type %s", nodetype2str(n->type));
}
if (do_lint && reference && var_uninitialized(n))
@@ -1346,7 +1346,7 @@ setup_frame(INSTRUCTION *pc)
break;
default:
- cant_happen();
+ cant_happen("unexpected parameter type %s", nodetype2str(m->type));
}
r->vname = fp[i].param;
}
diff --git a/interpret.h b/interpret.h
index 86a5c412..03adcd79 100644
--- a/interpret.h
+++ b/interpret.h
@@ -236,7 +236,7 @@ uninitialized_scalar:
break;
default:
- cant_happen();
+ cant_happen("unexpected parameter type %s", nodetype2str(m->type));
}
}
break;
@@ -427,7 +427,7 @@ uninitialized_scalar:
break;
default:
- cant_happen();
+ cant_happen("unexpected lint type value %d", (int) pc->lint_type);
}
}
break;
@@ -1260,7 +1260,7 @@ match_re:
}
case Op_K_return_from_eval:
- cant_happen();
+ cant_happen("unexpected opcode %s", opcode2str(op));
break;
case Op_K_return:
diff --git a/io.c b/io.c
index cf54cdd4..71745d24 100644
--- a/io.c
+++ b/io.c
@@ -841,7 +841,7 @@ redirect_string(const char *str, size_t explen, bool not_string,
what = "|&";
break;
default:
- cant_happen();
+ cant_happen("invalid redirection type %d", (int) redirtype);
}
if (do_lint && not_string)
lintwarn(_("expression in `%s' redirection is a number"),
@@ -1020,7 +1020,7 @@ redirect_string(const char *str, size_t explen, bool not_string,
}
break;
default:
- cant_happen();
+ cant_happen("invalid redirection type %d", (int) redirtype);
}
if (mode != NULL) {
@@ -1617,7 +1617,7 @@ str2mode(const char *mode)
default:
ret = 0; /* lint */
- cant_happen();
+ cant_happen("invalid open mode \"%s\"", mode);
}
if (strchr(mode, 'b') != NULL)
ret |= O_BINARY;
diff --git a/main.c b/main.c
index 515d9cdf..9e7762aa 100644
--- a/main.c
+++ b/main.c
@@ -1290,7 +1290,7 @@ catchsig(int sig)
fflush(NULL);
abort();
} else
- cant_happen();
+ cant_happen("unexpected signal, number %s", strsignal(sig));
/* NOTREACHED */
}
diff --git a/mpfr.c b/mpfr.c
index 25b7b467..dbaacb5c 100644
--- a/mpfr.c
+++ b/mpfr.c
@@ -496,7 +496,7 @@ mpg_update_var(NODE *n)
nr = FNR;
nq = MFNR;
} else
- cant_happen();
+ cant_happen("invalid node for mpg_update_var%s", "");
if (mpz_sgn(nq) == 0) {
/* Efficiency hack similar to that for AWKNUM */
@@ -528,7 +528,7 @@ mpg_set_var(NODE *n)
else if (n == FNR_node)
nq = MFNR;
else
- cant_happen();
+ cant_happen("invalid node for mpg_set_var%s", "");
if (is_mpg_integer(val))
r = val->mpg_i;
@@ -1847,7 +1847,7 @@ mod:
r = mpg_pow(t1, t2);
break;
default:
- cant_happen();
+ cant_happen("unexpected opcode %s", opcode2str(op));
}
DEREF(t2);
diff --git a/profile.c b/profile.c
index c17d633c..62e39e93 100644
--- a/profile.c
+++ b/profile.c
@@ -373,8 +373,7 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, int flags)
break;
default:
- fprintf(stderr, "Got unexpected type %s\n", nodetype2str(m->type));
- cant_happen();
+ cant_happen("got unexpected type %s", nodetype2str(m->type));
}
switch (pc->opcode) {
@@ -581,7 +580,7 @@ cleanup:
case Op_K_delete_loop:
/* Efficency hack not in effect because of exec_count instruction */
- cant_happen();
+ cant_happen("unexpected opcode %s", opcode2str(pc->opcode));
break;
case Op_in_array:
@@ -1219,7 +1218,7 @@ cleanup:
break;
default:
- cant_happen();
+ cant_happen("unexpected opcode %s", opcode2str(pc->opcode));
}
if (pc == endp)
diff --git a/re.c b/re.c
index fd134727..1caa57e9 100644
--- a/re.c
+++ b/re.c
@@ -144,7 +144,7 @@ make_regexp(const char *s, size_t len, bool ignorecase, bool dfa, bool canfatal)
case '7':
c2 = parse_escape(&src);
if (c2 < 0)
- cant_happen();
+ cant_happen("received bad result %d from parse_escape()", c2);
/*
* Unix awk treats octal (and hex?) chars
* literally in re's, so escape regexp
diff --git a/symbol.c b/symbol.c
index b89c01e0..78b29bba 100644
--- a/symbol.c
+++ b/symbol.c
@@ -631,7 +631,7 @@ load_symbols()
*aptr = dupnode(untyped);
break;
default:
- cant_happen();
+ cant_happen("unexpected node type %s", nodetype2str(r->type));
break;
}
}
@@ -922,7 +922,7 @@ free_bc_internal(INSTRUCTION *cp)
unref(m);
break;
case Op_illegal:
- cant_happen();
+ cant_happen("unexpected opcode %s", opcode2str(cp->opcode));
default:
break;
}