Skip to content

Commit

Permalink
lib: Avoid unnecessary Coverity warnings in MALLOC_*()
Browse files Browse the repository at this point in the history
There doesn't seem to be any other nice way of avoiding these without
separately marking every instance.
  • Loading branch information
sirainen committed Feb 10, 2017
1 parent ee92a55 commit ae9c5dd
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/lib/malloc-overflow.h
Expand Up @@ -20,8 +20,14 @@ malloc_multiply_check(size_t a, size_t b, size_t sizeof_a, size_t sizeof_b,
}
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,
Expand All @@ -36,7 +42,13 @@ malloc_add_check(size_t a, size_t b, size_t sizeof_a, size_t sizeof_b,
}
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

0 comments on commit ae9c5dd

Please sign in to comment.