# HG changeset patch # User Timo Sirainen # Date 1486720697 -7200 # Node ID bc9fe0a33b0a5dcc71e896deee39ad4f15d74fb7 # Parent 673a12afb3c55dda60e734faac56fc0ec0e0d4ef 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. diff -r 673a12afb3c5 -r bc9fe0a33b0a src/lib/malloc-overflow.h --- 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