safe one multiplication in overflow check for mempool_chcap()

Mon, 06 Mar 2017 16:22:42 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 06 Mar 2017 16:22:42 +0100
changeset 242
a3597d704421
parent 241
661f33ef20d8
child 243
2e74828c5e94

safe one multiplication in overflow check for mempool_chcap()

ucx/mempool.c file | annotate | diff | comparison | revisions
--- a/ucx/mempool.c	Mon Mar 06 16:09:42 2017 +0100
+++ b/ucx/mempool.c	Mon Mar 06 16:22:42 2017 +0100
@@ -109,8 +109,8 @@
 
 void *ucx_mempool_malloc(UcxMempool *pool, size_t n) {
     if (pool->ndata >= pool->size) {
-        if (pool->size*2 < pool->size /* overflow check */
-                || ucx_mempool_chcap(pool, pool->size*2)) {
+        size_t newcap = pool->size*2;
+        if (newcap < pool->size || ucx_mempool_chcap(pool, newcap)) {
             return NULL;
         }
     }

mercurial