malloc: simplify nasm_malloc code, add nasm_strcatn()
Simplify the nasm_malloc() code by moving the pointer check into a
common subroutine.
We can now issue a filename error even for failures like malloc().
Add support for the gcc sentinel attribute (verify that a list ends
with NULL).
Add a handful of safe_alloc attributes.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
diff --git a/include/compiler.h b/include/compiler.h
index fb146af..4178c98 100644
--- a/include/compiler.h
+++ b/include/compiler.h
@@ -264,7 +264,7 @@
#ifdef HAVE_FUNC_ATTRIBUTE_MALLOC
# define safe_alloc never_null __attribute__((malloc))
#else
-# define safe_alloc
+# define safe_alloc never_null
#endif
#ifdef HAVE_FUNC_ATTRIBUTE_ALLOC_SIZE
@@ -277,6 +277,12 @@
# define safe_realloc(s) never_null
#endif
+#ifdef HAVE_FUNC_ATTRIBUTE_SENTINEL
+# define end_with_null __attribute__((sentinel))
+#else
+# define end_with_null
+#endif
+
/*
* How to tell the compiler that a function doesn't return
*/