diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2022-02-27 20:39:54 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2022-02-27 20:39:54 +0200 |
commit | fc1410099d6ccbb72adb54ecffd0711348706ca4 (patch) | |
tree | d04175556415fff6bcf66f48fc05c4da5f2d4908 | |
parent | 7acb038bd54f81fb95dac70954e5c1b8ec07a086 (diff) | |
download | egawk-fc1410099d6ccbb72adb54ecffd0711348706ca4.tar.gz egawk-fc1410099d6ccbb72adb54ecffd0711348706ca4.tar.bz2 egawk-fc1410099d6ccbb72adb54ecffd0711348706ca4.zip |
Have cant_happen() give more information.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | awk.h | 4 | ||||
-rw-r--r-- | awkgram.c | 10 | ||||
-rw-r--r-- | awkgram.y | 10 | ||||
-rw-r--r-- | debug.c | 2 | ||||
-rw-r--r-- | eval.c | 4 | ||||
-rw-r--r-- | interpret.h | 6 | ||||
-rw-r--r-- | io.c | 6 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | mpfr.c | 6 | ||||
-rw-r--r-- | profile.c | 7 | ||||
-rw-r--r-- | re.c | 2 | ||||
-rw-r--r-- | symbol.c | 4 |
13 files changed, 39 insertions, 32 deletions
@@ -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 @@ -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__)) @@ -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; @@ -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; @@ -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)); } } @@ -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: @@ -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; @@ -1290,7 +1290,7 @@ catchsig(int sig) fflush(NULL); abort(); } else - cant_happen(); + cant_happen("unexpected signal, number %s", strsignal(sig)); /* NOTREACHED */ } @@ -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); @@ -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) @@ -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 @@ -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; } |