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 bbbf508394

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
H. Peter Anvin 2016-02-17 16:10:41 -08:00 committed by H. Peter Anvin
parent c5b2de0964
commit 7f087afc66
2 changed files with 15 additions and 5 deletions

View file

@ -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;

View file

@ -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__);