mirror of
https://github.com/netwide-assembler/nasm
synced 2026-08-26 16:23:04 -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:
parent
1ce81e10ef
commit
740ec3572b
5 changed files with 85 additions and 22 deletions
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -79,6 +79,8 @@ void * safe_realloc(2) nasm_realloc(void *, size_t);
|
|||
void nasm_free(void *);
|
||||
char * safe_alloc nasm_strdup(const char *);
|
||||
char * safe_alloc nasm_strndup(const char *, size_t);
|
||||
char * safe_alloc nasm_strcat(const char *one, const char *two);
|
||||
char * safe_alloc end_with_null nasm_strcatn(const char *one, ...);
|
||||
|
||||
/* Assert the argument is a pointer without evaluating it */
|
||||
#define nasm_assert_pointer(p) ((void)sizeof(*(p)))
|
||||
|
|
@ -282,8 +284,6 @@ void src_set(int32_t line, const char *filename);
|
|||
*/
|
||||
int32_t src_get(int32_t *xline, const char **xname);
|
||||
|
||||
char *nasm_strcat(const char *one, const char *two);
|
||||
|
||||
char *nasm_skip_spaces(const char *p);
|
||||
char *nasm_skip_word(const char *p);
|
||||
char *nasm_zap_spaces_fwd(char *p);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue