Revert "alloc-util: return NULL if 0-sized allocation is requested"
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 13 Oct 2018 08:45:14 +0000 (17:45 +0900)
committerLennart Poettering <lennart@poettering.net>
Sat, 13 Oct 2018 10:34:32 +0000 (12:34 +0200)
This reverts commit c05107767b589e9aac9711eb385738887f86eb77.

src/basic/alloc-util.h

index 62b5911..ebe4288 100644 (file)
@@ -52,11 +52,8 @@ 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 == 0 || size > (SIZE_MAX / need));
+        return _unlikely_(need != 0 && size > (SIZE_MAX / need));
 }
 
 _malloc_  _alloc_(1, 2) static inline void *malloc_multiply(size_t size, size_t need) {