From: Todd C. Miller Date: Tue, 5 Mar 2013 15:18:32 +0000 (-0500) Subject: Add __malloc_like macro to apply __malloc__ attribute to emalloc, X-Git-Tag: SUDO_1_8_7~1^2~188 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4e5baccb9c98b602aecc9f659bdd5b1527bf6a88;p=sudo 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. --- diff --git a/include/alloc.h b/include/alloc.h index b5b3e381d..77ba2a289 100644 --- a/include/alloc.h +++ b/include/alloc.h @@ -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 */ diff --git a/include/missing.h b/include/missing.h index 8276065cf..ddb6a05e5 100644 --- a/include/missing.h +++ b/include/missing.h @@ -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__)