Merge pull request #10356 from dtardon/covscan

assorted coverity/clang fixes
This commit is contained in:
Lennart Poettering
2018-10-12 18:43:04 +02:00
committed by GitHub
12 changed files with 38 additions and 17 deletions
+4 -1
View File
@@ -52,8 +52,11 @@ static inline void freep(void *p) {
#define _cleanup_free_ _cleanup_(freep)
/* Checks the size arguments of allocation functions for overflow in multiplication. In addition, checks if either of
* them is 0; that is almost certainly an error (e.g., an overflow in computing _need_), so it's better to fail (and
* we cannot leave this check to malloc, because the behavior of malloc(0) is impl. specific). */
static inline bool size_multiply_overflow(size_t size, size_t need) {
return _unlikely_(need != 0 && size > (SIZE_MAX / need));
return _unlikely_(need == 0 || size == 0 || size > (SIZE_MAX / need));
}
_malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t size, size_t need) {