0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-09-22 10:43:39 -04:00

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>
This commit is contained in:
H. Peter Anvin
2018-05-30 11:40:42 -07:00
parent 1ce81e10ef
commit 740ec3572b
5 changed files with 85 additions and 22 deletions

View File

@@ -264,7 +264,7 @@ size_t strnlen(const char *s, size_t maxlen);
#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 @@ size_t strnlen(const char *s, size_t maxlen);
# 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
*/