summaryrefslogtreecommitdiff
path: root/src/shared/util.h
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2014-06-13 18:38:15 +0200
committerDavid Herrmann <dh.herrmann@gmail.com>2014-06-16 15:22:57 +0200
commit368504f485d09b9fd48b7538e71981f648eb32bb (patch)
tree212099b3f05d91408cdeba2c42261bf4e073b8da /src/shared/util.h
parentd442e2ec6e896c312bc616be7607332d978a45c9 (diff)
util: fix multiply-alloc helpers with size==0
Passing 0 to malloc() is not required to return NULL. Therefore, don't bail out if "b" is 0. This is not of importance to the existing helpers, but the upcoming realloc_multiply() requires this. To keep consistence, we keep the same behavior for the other helpers.
Diffstat (limited to 'src/shared/util.h')
-rw-r--r--src/shared/util.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/shared/util.h b/src/shared/util.h
index e8552410c0..5a2f10387e 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -666,14 +666,14 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, endmntent);
#define _cleanup_close_pair_ _cleanup_(close_pairp)
_malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t a, size_t b) {
- if (_unlikely_(b == 0 || a > ((size_t) -1) / b))
+ if (_unlikely_(b != 0 && a > ((size_t) -1) / b))
return NULL;
return malloc(a * b);
}
_alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t a, size_t b) {
- if (_unlikely_(b == 0 || a > ((size_t) -1) / b))
+ if (_unlikely_(b != 0 && a > ((size_t) -1) / b))
return NULL;
return memdup(p, a * b);