diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-10-26 14:17:17 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-10-26 14:17:17 +0100 |
commit | 7f702c6f3416f85238a48794c86bc8cb334e4df6 (patch) | |
tree | 565a29727807ce0f5ef2504bb94f6c4acc4de030 /src | |
parent | 4e68457c2f6d3148c6da3020affe4dc7f918f5cc (diff) | |
download | rspamd-7f702c6f3416f85238a48794c86bc8cb334e4df6.tar.gz rspamd-7f702c6f3416f85238a48794c86bc8cb334e4df6.zip |
[Minor] Add more attributes
Diffstat (limited to 'src')
-rw-r--r-- | src/libutil/mem_pool.c | 10 | ||||
-rw-r--r-- | src/libutil/mem_pool.h | 18 |
2 files changed, 20 insertions, 8 deletions
diff --git a/src/libutil/mem_pool.c b/src/libutil/mem_pool.c index 322ebc409..4efd71231 100644 --- a/src/libutil/mem_pool.c +++ b/src/libutil/mem_pool.c @@ -163,6 +163,7 @@ rspamd_mempool_get_entry (const gchar *loc) return rspamd_mempool_entry_new (loc); } + static struct _pool_chain * rspamd_mempool_chain_new (gsize size, enum rspamd_mempool_chain_type pool_type) { @@ -171,7 +172,7 @@ rspamd_mempool_chain_new (gsize size, enum rspamd_mempool_chain_type pool_type) optimal_size = 0; gpointer map; - g_return_val_if_fail (size > 0, NULL); + g_assert (size > 0); if (pool_type == RSPAMD_MEMPOOL_SHARED) { #if defined(HAVE_MMAP_ANON) @@ -401,6 +402,11 @@ rspamd_mempool_new_ (gsize size, const gchar *tag, const gchar *loc) static void * memory_pool_alloc_common (rspamd_mempool_t * pool, gsize size, + enum rspamd_mempool_chain_type pool_type) +RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL; + +static void * +memory_pool_alloc_common (rspamd_mempool_t * pool, gsize size, enum rspamd_mempool_chain_type pool_type) { guint8 *tmp; @@ -464,7 +470,7 @@ memory_pool_alloc_common (rspamd_mempool_t * pool, gsize size, return tmp; } - return NULL; + g_abort (); } diff --git a/src/libutil/mem_pool.h b/src/libutil/mem_pool.h index 14f74522c..9b6f690c7 100644 --- a/src/libutil/mem_pool.h +++ b/src/libutil/mem_pool.h @@ -33,9 +33,15 @@ struct f_str_s; # else # #define RSPAMD_ATTR_ALLOC_ALIGN(al) # endif +# if __has_attribute(returns_nonnull) +# define RSPAMD_ATTR_RETURNS_NONNUL __attribute__((returns_nonnull)) +# else +# #define RSPAMD_ATTR_RETURNS_NONNUL +# endif #else #define RSPAMD_ATTR_ALLOC_SIZE(pos) #define RSPAMD_ATTR_ALLOC_ALIGN(al) +#define RSPAMD_ATTR_RETURNS_NONNUL #endif #define MEMPOOL_TAG_LEN 20 @@ -151,7 +157,7 @@ rspamd_mempool_t * rspamd_mempool_new_ (gsize size, const gchar *tag, const gcha * @return pointer to allocated object */ void * rspamd_mempool_alloc (rspamd_mempool_t * pool, gsize size) - RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MEM_ALIGNMENT); + RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL; /** * Get memory from temporary pool @@ -159,7 +165,7 @@ void * rspamd_mempool_alloc (rspamd_mempool_t * pool, gsize size) * @param size bytes to allocate * @return pointer to allocated object */ -void * rspamd_mempool_alloc_tmp (rspamd_mempool_t * pool, gsize size); +void * rspamd_mempool_alloc_tmp (rspamd_mempool_t * pool, gsize size) RSPAMD_ATTR_RETURNS_NONNUL; /** * Get memory and set it to zero @@ -168,7 +174,7 @@ void * rspamd_mempool_alloc_tmp (rspamd_mempool_t * pool, gsize size); * @return pointer to allocated object */ void * rspamd_mempool_alloc0 (rspamd_mempool_t * pool, gsize size) - RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MEM_ALIGNMENT); + RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL; /** * Get memory and set it to zero @@ -176,7 +182,7 @@ void * rspamd_mempool_alloc0 (rspamd_mempool_t * pool, gsize size) * @param size bytes to allocate * @return pointer to allocated object */ -void * rspamd_mempool_alloc0_tmp (rspamd_mempool_t * pool, gsize size); +void * rspamd_mempool_alloc0_tmp (rspamd_mempool_t * pool, gsize size) RSPAMD_ATTR_RETURNS_NONNUL; /** * Cleanup temporary data in pool @@ -218,9 +224,9 @@ gchar * rspamd_mempool_ftokdup (rspamd_mempool_t *pool, * @param size bytes to allocate */ void * rspamd_mempool_alloc_shared (rspamd_mempool_t * pool, gsize size) - RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MEM_ALIGNMENT); + RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL; void * rspamd_mempool_alloc0_shared (rspamd_mempool_t *pool, gsize size) - RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MEM_ALIGNMENT); + RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL; /** * Add destructor callback to pool * @param pool memory pool object |