Add __malloc_like macro to apply __malloc__ attribute to emalloc,

ecalloc and estrdup.  It cannot be applied to realloc since that
may return the same pointer.
This commit is contained in:
Todd C. Miller
2013-03-05 10:18:32 -05:00
parent c47f5f7abd
commit 4e5baccb9c
2 changed files with 14 additions and 5 deletions

View File

@@ -22,13 +22,13 @@
int easprintf(char **, const char *, ...) __printflike(2, 3);
int evasprintf(char **, const char *, va_list) __printflike(2, 0);
void efree(void *);
void *ecalloc(size_t, size_t);
void *emalloc(size_t);
void *emalloc2(size_t, size_t);
void *ecalloc(size_t, size_t) __malloc_like;
void *emalloc(size_t) __malloc_like;
void *emalloc2(size_t, size_t) __malloc_like;
void *erealloc(void *, size_t);
void *erealloc3(void *, size_t, size_t);
void *erecalloc(void *, size_t, size_t, size_t);
char *estrdup(const char *);
char *estrndup(const char *, size_t);
char *estrdup(const char *) __malloc_like;
char *estrndup(const char *, size_t) __malloc_like;
#endif /* _SUDO_ALLOC_H */

View File

@@ -52,6 +52,15 @@
# endif
#endif
/* Hint to compiler that returned pointer is unique (malloc but not realloc). */
#ifndef __malloc_like
# if __GNUC_PREREQ__(2, 96)
# define __malloc_like __attribute__((__malloc__))
# else
# define __malloc_like
# endif
#endif
#ifndef __dso_public
# ifdef HAVE_DSO_VISIBILITY
# if defined(__GNUC__)