Mercurial > dovecot > core-2.2
changeset 21509:bc9fe0a33b0a
lib: Avoid unnecessary Coverity warnings in MALLOC_*()
There doesn't seem to be any other nice way of avoiding these without
separately marking every instance.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Fri, 10 Feb 2017 11:58:17 +0200 |
parents | 673a12afb3c5 |
children | ea1d4d6e5493 |
files | src/lib/malloc-overflow.h |
diffstat | 1 files changed, 14 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/malloc-overflow.h Thu Feb 09 16:33:35 2017 +0200 +++ b/src/lib/malloc-overflow.h Fri Feb 10 11:58:17 2017 +0200 @@ -20,8 +20,14 @@ } return a * b; } -#define MALLOC_MULTIPLY(a, b) \ +#ifndef STATIC_CHECKER +# define MALLOC_MULTIPLY(a, b) \ malloc_multiply_check(a, b, sizeof(a), sizeof(b), __FILE__, __LINE__) +#else +/* avoid warning every time about sizeof(b) when b contains any arithmetic */ +# define MALLOC_MULTIPLY(a, b) \ + malloc_multiply_check(a, b, sizeof(a), sizeof(size_t), __FILE__, __LINE__) +#endif static inline size_t malloc_add_check(size_t a, size_t b, size_t sizeof_a, size_t sizeof_b, @@ -36,7 +42,13 @@ } return a + b; } -#define MALLOC_ADD(a, b) \ +#ifndef STATIC_CHECKER +# define MALLOC_ADD(a, b) \ malloc_add_check(a, b, sizeof(a), sizeof(b), __FILE__, __LINE__) +#else +/* avoid warning every time about sizeof(b) when b contains any arithmetic */ +# define MALLOC_ADD(a, b) \ + malloc_add_check(a, b, sizeof(a), sizeof(size_t), __FILE__, __LINE__) +#endif #endif