summaryrefslogtreecommitdiff
path: root/disasm
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2019-08-28 18:32:46 -0700
committerH. Peter Anvin <hpa@zytor.com>2019-08-28 18:32:46 -0700
commit6a4353c4c29274fb2df6ca712fad70b8701c9187 (patch)
tree81456594614ae6120f6b1f0746d3c146ee890539 /disasm
parentf8a15a8ea3cc3484f4250fd878569f15412434ab (diff)
downloadnasm-6a4353c4c29274fb2df6ca712fad70b8701c9187.tar.gz
errors: be more robust in handling unexpected fatal errors
Introduce a new error level, ERR_CRITICAL, beyond which we will minimize the amount of code that will be executed before we die; in particular don't execute any memory allocations, and if we somehow end up recursing, abort() immediately. Basically, "less than panic, more than fatal." At this point this level is used by nasm_alloc_failed(). Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'disasm')
-rw-r--r--disasm/ndisasm.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/disasm/ndisasm.c b/disasm/ndisasm.c
index 6b4ca49d..3269c367 100644
--- a/disasm/ndisasm.c
+++ b/disasm/ndisasm.c
@@ -65,12 +65,18 @@ static const char *help =
static void output_ins(uint64_t, uint8_t *, int, char *);
static void skip(uint32_t dist, FILE * fp);
-static void ndisasm_verror(errflags severity, const char *fmt, va_list va)
+fatal_func nasm_verror_critical(errflags severity, const char *fmt, va_list val)
{
- vfprintf(stderr, fmt, va);
+ vfprintf(stderr, fmt, val);
+ exit((severity & ERR_MASK) - ERR_FATAL + 2);
+}
- if (severity & ERR_FATAL)
- exit(1);
+static void ndisasm_verror(errflags severity, const char *fmt, va_list val)
+{
+ if ((severity & ERR_MASK) >= ERR_FATAL)
+ nasm_verror_critical(severity, fmt, val);
+ else
+ vfprintf(stderr, fmt, val);
}
int main(int argc, char **argv)