summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2016-02-17 16:10:41 -0800
committerH. Peter Anvin <hpa@zytor.com>2016-03-03 15:22:02 -0800
commit7f087afc6633197416c036976858ef3565ed3cc8 (patch)
tree56d8236a8b05f6ce9435c74d0722d2a0fe6b9931
parentc5b2de096436661892c13ec2c645e6d643c800f7 (diff)
downloadnasm-7f087afc6633197416c036976858ef3565ed3cc8.tar.gz
nasmlib: add nasm_fatal() like nasm_panic()
Just like nasm_panic(), nasm_fatal() tells the compiler that we can never return from this call. From master branch checkin bbbf50839479a63841169b8995f285fb1c8a3fc5 Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
-rw-r--r--nasmlib.c19
-rw-r--r--nasmlib.h1
2 files changed, 15 insertions, 5 deletions
diff --git a/nasmlib.c b/nasmlib.c
index cf39468a..d19cbf6d 100644
--- a/nasmlib.c
+++ b/nasmlib.c
@@ -83,6 +83,15 @@ void nasm_error(int severity, const char *fmt, ...)
va_end(ap);
}
+no_return nasm_fatal(int flags, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ nasm_verror(flags | ERR_FATAL, fmt, ap);
+ abort(); /* We should never get here */
+}
+
no_return nasm_panic(int flags, const char *fmt, ...)
{
va_list ap;
@@ -101,7 +110,7 @@ void *nasm_malloc(size_t size)
{
void *p = malloc(size);
if (!p)
- nasm_error(ERR_FATAL | ERR_NOFILE, "out of memory");
+ nasm_fatal(ERR_NOFILE, "out of memory");
return p;
}
@@ -109,7 +118,7 @@ void *nasm_zalloc(size_t size)
{
void *p = calloc(size, 1);
if (!p)
- nasm_error(ERR_FATAL | ERR_NOFILE, "out of memory");
+ nasm_fatal(ERR_NOFILE, "out of memory");
return p;
}
@@ -117,7 +126,7 @@ void *nasm_realloc(void *q, size_t size)
{
void *p = q ? realloc(q, size) : malloc(size);
if (!p)
- nasm_error(ERR_FATAL | ERR_NOFILE, "out of memory");
+ nasm_fatal(ERR_NOFILE, "out of memory");
return p;
}
@@ -134,7 +143,7 @@ char *nasm_strdup(const char *s)
p = malloc(size);
if (!p)
- nasm_error(ERR_FATAL | ERR_NOFILE, "out of memory");
+ nasm_fatal(ERR_NOFILE, "out of memory");
strcpy(p, s);
return p;
}
@@ -146,7 +155,7 @@ char *nasm_strndup(const char *s, size_t len)
p = malloc(size);
if (!p)
- nasm_error(ERR_FATAL | ERR_NOFILE, "out of memory");
+ nasm_fatal(ERR_NOFILE, "out of memory");
strncpy(p, s, len);
p[len] = '\0';
return p;
diff --git a/nasmlib.h b/nasmlib.h
index 86766e37..2e2e807f 100644
--- a/nasmlib.h
+++ b/nasmlib.h
@@ -77,6 +77,7 @@ typedef void (*efunc) (int severity, const char *fmt, ...);
typedef void (*vefunc) (int severity, const char *fmt, va_list ap);
void printf_func(2, 3) nasm_error(int severity, const char *fmt, ...);
void nasm_set_verror(vefunc);
+no_return printf_func(2, 3) nasm_fatal(int flags, const char *fmt, ...);
no_return printf_func(2, 3) nasm_panic(int flags, const char *fmt, ...);
no_return nasm_panic_from_macro(const char *file, int line);
#define panic() nasm_panic_from_macro(__FILE__, __LINE__);