dovecot-2.2: lib: Use __attribute__((returns_nonnull)) for the c...

dovecot at dovecot.org dovecot at dovecot.org
Mon Jun 16 15:09:13 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/6abf982c268d
changeset: 17502:6abf982c268d
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jun 16 18:01:58 2014 +0300
description:
lib: Use __attribute__((returns_nonnull)) for the common memory/string functions.
Also added a couple of missing ATTR_MALLOCs.

diffstat:

 src/lib/data-stack.h |   8 ++++----
 src/lib/imem.h       |  11 ++++++-----
 src/lib/macros.h     |   6 ++++++
 src/lib/mempool.h    |   8 ++++----
 src/lib/strfuncs.h   |  31 +++++++++++++++++--------------
 5 files changed, 37 insertions(+), 27 deletions(-)

diffs (201 lines):

diff -r 5de6a5f241db -r 6abf982c268d src/lib/data-stack.h
--- a/src/lib/data-stack.h	Mon Jun 16 17:40:51 2014 +0300
+++ b/src/lib/data-stack.h	Mon Jun 16 18:01:58 2014 +0300
@@ -61,8 +61,8 @@
 
    t_malloc() calls never fail. If there's not enough memory left,
    i_panic() will be called. */
-void *t_malloc(size_t size) ATTR_MALLOC;
-void *t_malloc0(size_t size) ATTR_MALLOC;
+void *t_malloc(size_t size) ATTR_MALLOC ATTR_RETURNS_NONNULL;
+void *t_malloc0(size_t size) ATTR_MALLOC ATTR_RETURNS_NONNULL;
 
 /* Try growing allocated memory. Returns TRUE if successful. Works only
    for last allocated memory in current stack frame. */
@@ -84,12 +84,12 @@
    new one (or do some other trickery). See t_buffer_reget(). */
 #define t_buffer_get_type(type, size) \
 	t_buffer_get(sizeof(type) * (size))
-void *t_buffer_get(size_t size);
+void *t_buffer_get(size_t size) ATTR_RETURNS_NONNULL;
 
 /* Grow the buffer, memcpy()ing the memory to new location if needed. */
 #define t_buffer_reget_type(buffer, type, size) \
 	t_buffer_reget(buffer, sizeof(type) * (size))
-void *t_buffer_reget(void *buffer, size_t size);
+void *t_buffer_reget(void *buffer, size_t size) ATTR_RETURNS_NONNULL;
 
 /* Make the last t_buffer_get()ed buffer permanent. Note that size MUST be
    less or equal than the size you gave with last t_buffer_get() or the
diff -r 5de6a5f241db -r 6abf982c268d src/lib/imem.h
--- a/src/lib/imem.h	Mon Jun 16 17:40:51 2014 +0300
+++ b/src/lib/imem.h	Mon Jun 16 18:01:58 2014 +0300
@@ -7,9 +7,9 @@
 
 #define i_new(type, count) p_new(default_pool, type, count)
 
-void *i_malloc(size_t size) ATTR_MALLOC;
+void *i_malloc(size_t size) ATTR_MALLOC ATTR_RETURNS_NONNULL;
 void *i_realloc(void *mem, size_t old_size, size_t new_size)
-	ATTR_WARN_UNUSED_RESULT;
+	ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL;
 
 #define i_free(mem) p_free(default_pool, mem)
 #define i_free_and_null(mem) p_free_and_null(default_pool, mem)
@@ -19,12 +19,13 @@
 /* like i_strdup(), but if str == "", return NULL */
 char *i_strdup_empty(const char *str) ATTR_MALLOC;
 /* *end isn't included */
-char *i_strdup_until(const void *str, const void *end) ATTR_MALLOC;
+char *i_strdup_until(const void *str, const void *end)
+	ATTR_MALLOC ATTR_RETURNS_NONNULL;
 char *i_strndup(const void *str, size_t max_chars) ATTR_MALLOC;
 char *i_strdup_printf(const char *format, ...)
-	ATTR_FORMAT(1, 2) ATTR_MALLOC;
+	ATTR_FORMAT(1, 2) ATTR_MALLOC ATTR_RETURNS_NONNULL;
 char *i_strdup_vprintf(const char *format, va_list args)
-	ATTR_FORMAT(1, 0) ATTR_MALLOC;
+	ATTR_FORMAT(1, 0) ATTR_MALLOC ATTR_RETURNS_NONNULL;
 
 char *i_strconcat(const char *str1, ...)  ATTR_SENTINEL ATTR_MALLOC;
 
diff -r 5de6a5f241db -r 6abf982c268d src/lib/macros.h
--- a/src/lib/macros.h	Mon Jun 16 17:40:51 2014 +0300
+++ b/src/lib/macros.h	Mon Jun 16 18:01:58 2014 +0300
@@ -140,6 +140,12 @@
 #  define ATTR_HOT
 #  define ATTR_COLD
 #endif
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
+/* GCC 4.9 and later */
+#  define ATTR_RETURNS_NONNULL __attribute__((returns_nonnull))
+#else
+#  define ATTR_RETURNS_NONNULL
+#endif
 
 /* Macros to provide type safety for callback functions' context parameters */
 #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3))
diff -r 5de6a5f241db -r 6abf982c268d src/lib/mempool.h
--- a/src/lib/mempool.h	Mon Jun 16 17:40:51 2014 +0300
+++ b/src/lib/mempool.h	Mon Jun 16 18:01:58 2014 +0300
@@ -22,13 +22,13 @@
 	void (*ref)(pool_t pool);
 	void (*unref)(pool_t *pool);
 
-	void *(*malloc)(pool_t pool, size_t size);
+	void *(*malloc)(pool_t pool, size_t size) ATTR_RETURNS_NONNULL;
 	void (*free)(pool_t pool, void *mem);
 
 	/* memory in old_size..new_size will be zeroed */
 	void *(*realloc)(pool_t pool, void *mem,
 			 size_t old_size, size_t new_size)
-		ATTR_WARN_UNUSED_RESULT;
+		ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL;
 
 	/* Frees all the memory in pool. NOTE: system_pool doesn't support
 	   this and crashes if it's used */
@@ -70,13 +70,13 @@
 
 #define p_new(pool, type, count) \
 	((type *) p_malloc(pool, sizeof(type) * (count)))
-static inline void * ATTR_MALLOC
+static inline void * ATTR_MALLOC ATTR_RETURNS_NONNULL
 p_malloc(pool_t pool, size_t size)
 {
 	return pool->v->malloc(pool, size);
 }
 
-static inline void * ATTR_WARN_UNUSED_RESULT
+static inline void * ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
 p_realloc(pool_t pool, void *mem, size_t old_size, size_t new_size)
 {
 	return pool->v->realloc(pool, mem, old_size, new_size);
diff -r 5de6a5f241db -r 6abf982c268d src/lib/strfuncs.h
--- a/src/lib/strfuncs.h	Mon Jun 16 17:40:51 2014 +0300
+++ b/src/lib/strfuncs.h	Mon Jun 16 18:01:58 2014 +0300
@@ -14,12 +14,12 @@
 char *p_strdup_empty(pool_t pool, const char *str) ATTR_MALLOC;
 /* *end isn't included */
 char *p_strdup_until(pool_t pool, const void *start, const void *end)
-	ATTR_MALLOC;
+	ATTR_MALLOC ATTR_RETURNS_NONNULL;
 char *p_strndup(pool_t pool, const void *str, size_t max_chars) ATTR_MALLOC;
 char *p_strdup_printf(pool_t pool, const char *format, ...)
-	ATTR_FORMAT(2, 3) ATTR_MALLOC;
+	ATTR_FORMAT(2, 3) ATTR_MALLOC ATTR_RETURNS_NONNULL;
 char *p_strdup_vprintf(pool_t pool, const char *format, va_list args)
-	ATTR_FORMAT(2, 0) ATTR_MALLOC;
+	ATTR_FORMAT(2, 0) ATTR_MALLOC ATTR_RETURNS_NONNULL;
 char *p_strconcat(pool_t pool, const char *str1, ...)
 	ATTR_SENTINEL ATTR_MALLOC;
 
@@ -29,12 +29,13 @@
 /* return NULL if str = "" */
 const char *t_strdup_empty(const char *str) ATTR_MALLOC;
 /* *end isn't included */
-const char *t_strdup_until(const void *start, const void *end) ATTR_MALLOC;
+const char *t_strdup_until(const void *start, const void *end)
+	ATTR_MALLOC ATTR_RETURNS_NONNULL;
 const char *t_strndup(const void *str, size_t max_chars) ATTR_MALLOC;
 const char *t_strdup_printf(const char *format, ...)
-	ATTR_FORMAT(1, 2) ATTR_MALLOC;
+	ATTR_FORMAT(1, 2) ATTR_MALLOC ATTR_RETURNS_NONNULL;
 const char *t_strdup_vprintf(const char *format, va_list args)
-	ATTR_FORMAT(1, 0) ATTR_MALLOC;
+	ATTR_FORMAT(1, 0) ATTR_MALLOC ATTR_RETURNS_NONNULL;
 const char *t_strconcat(const char *str1, ...)
 	ATTR_SENTINEL ATTR_MALLOC;
 
@@ -59,18 +60,18 @@
 /* separators is an array of separator characters, not a separator string.
    an empty data string results in an array containing only NULL. */
 char **p_strsplit(pool_t pool, const char *data, const char *separators)
-	ATTR_MALLOC;
+	ATTR_MALLOC ATTR_RETURNS_NONNULL;
 const char **t_strsplit(const char *data, const char *separators)
-	ATTR_MALLOC;
+	ATTR_MALLOC ATTR_RETURNS_NONNULL;
 /* like p_strsplit(), but treats multiple adjacent separators as a single
    separator. */
 char **p_strsplit_spaces(pool_t pool, const char *data, const char *separators)
-	ATTR_MALLOC;
+	ATTR_MALLOC ATTR_RETURNS_NONNULL;
 const char **t_strsplit_spaces(const char *data, const char *separators)
-	ATTR_MALLOC;
+	ATTR_MALLOC ATTR_RETURNS_NONNULL;
 void p_strsplit_free(pool_t pool, char **arr);
 /* Optimized version of t_strsplit(data, "\t") */
-const char **t_strsplit_tab(const char *data);
+const char **t_strsplit_tab(const char *data) ATTR_MALLOC ATTR_RETURNS_NONNULL;
 
 const char *dec2str(uintmax_t number);
 
@@ -78,7 +79,7 @@
 unsigned int str_array_length(const char *const *arr) ATTR_PURE;
 /* Return all strings from array joined into one string. */
 const char *t_strarray_join(const char *const *arr, const char *separator)
-	ATTR_MALLOC;
+	ATTR_MALLOC ATTR_RETURNS_NONNULL;
 /* Removes a value from NULL-terminated string array. Returns TRUE if found. */
 bool str_array_remove(const char **arr, const char *value);
 /* Returns TRUE if value exists in NULL-terminated string array. */
@@ -87,7 +88,8 @@
 bool str_array_icase_find(const char *const *arr, const char *value);
 /* Duplicate array of strings. The memory can be freed by freeing the
    return value. */
-const char **p_strarray_dup(pool_t pool, const char *const *arr);
+const char **p_strarray_dup(pool_t pool, const char *const *arr)
+	ATTR_MALLOC ATTR_RETURNS_NONNULL;
 
 #define i_qsort(base, nmemb, size, cmp) \
 	qsort(base, nmemb, size + \
@@ -103,7 +105,8 @@
 
 /* INTERNAL */
 char *t_noalloc_strdup_vprintf(const char *format, va_list args,
-			       unsigned int *size_r) ATTR_FORMAT(1, 0);
+			       unsigned int *size_r)
+	ATTR_FORMAT(1, 0) ATTR_RETURNS_NONNULL;
 char *vstrconcat(const char *str1, va_list args, size_t *ret_len) ATTR_MALLOC;
 
 #endif


More information about the dovecot-cvs mailing list