]> granicus.if.org Git - sudo/commitdiff
Add __malloc_like macro to apply __malloc__ attribute to emalloc,
authorTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 5 Mar 2013 15:18:32 +0000 (10:18 -0500)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 5 Mar 2013 15:18:32 +0000 (10:18 -0500)
ecalloc and estrdup.  It cannot be applied to realloc since that
may return the same pointer.

include/alloc.h
include/missing.h

index b5b3e381d267f0b3ef40011326ac451937c188b3..77ba2a28913ae19014c897b9d47c27dd1eb668ca 100644 (file)
 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 */
index 8276065cfbe1f2c3ea9a238f1bec22923ec49277..ddb6a05e5c5b41ca97c1783ee8c0c54a07f95fb9 100644 (file)
 # 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__)