libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 16c9a00cb7dc06ee4ef988f443da7c1ad780b3f6
parent d49359450cc6048df6fad758f2078b429dce28d8
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Wed, 12 Jun 2019 17:18:24 +0300

memorypool.c: added asserts

Diffstat:
Msrc/microhttpd/memorypool.c | 22+++++++++++++++++++++-
Msrc/microhttpd/memorypool.h | 4+++-
2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/microhttpd/memorypool.c b/src/microhttpd/memorypool.c @@ -1,6 +1,7 @@ /* This file is part of libmicrohttpd - Copyright (C) 2007, 2009, 2010 Daniel Pittman and Christian Grothoff + Copyright (C) 2007--2019 Daniel Pittman, Christian Grothoff and + Karlson2k (Evgeny Grin) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -21,8 +22,10 @@ * @file memorypool.c * @brief memory pool * @author Christian Grothoff + * @author Karlson2k (Evgeny Grin) */ #include "memorypool.h" +#include "mhd_assert.h" /* define MAP_ANONYMOUS for Mac OS X */ #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) @@ -158,6 +161,9 @@ MHD_pool_destroy (struct MemoryPool *pool) { if (NULL == pool) return; + + mhd_assert (pool->end >= pool->pos); + mhd_assert (pool->size >= pool->end - pool->pos); if (MHD_NO == pool->is_mmap) free (pool->memory); else @@ -184,6 +190,8 @@ MHD_pool_destroy (struct MemoryPool *pool) size_t MHD_pool_get_free (struct MemoryPool *pool) { + mhd_assert (pool->end >= pool->pos); + mhd_assert (pool->size >= pool->end - pool->pos); return (pool->end - pool->pos); } @@ -207,6 +215,8 @@ MHD_pool_allocate (struct MemoryPool *pool, void *ret; size_t asize; + mhd_assert (pool->end >= pool->pos); + mhd_assert (pool->size >= pool->end - pool->pos); asize = ROUND_TO_ALIGN (size); if ( (0 == asize) && (0 != size) ) return NULL; /* size too close to SIZE_MAX */ @@ -253,6 +263,11 @@ MHD_pool_reallocate (struct MemoryPool *pool, void *ret; size_t asize; + mhd_assert (pool->end >= pool->pos); + mhd_assert (pool->size >= pool->end - pool->pos); + mhd_assert (old != NULL || old_size == 0); + mhd_assert (old == NULL || pool->memory <= (char*)old); + mhd_assert (old == NULL || pool->memory + pool->size >= (char*)old + old_size); asize = ROUND_TO_ALIGN (new_size); if ( (0 == asize) && (0 != new_size) ) @@ -316,6 +331,11 @@ MHD_pool_reset (struct MemoryPool *pool, size_t copy_bytes, size_t new_size) { + mhd_assert (pool->end >= pool->pos); + mhd_assert (pool->size >= pool->end - pool->pos); + mhd_assert (keep != NULL || copy_bytes == 0); + mhd_assert (keep == NULL || pool->memory <= (char*)keep); + mhd_assert (keep == NULL || pool->memory + pool->size >= (char*)keep + copy_bytes); if ( (NULL != keep) && (keep != pool->memory) ) { diff --git a/src/microhttpd/memorypool.h b/src/microhttpd/memorypool.h @@ -1,6 +1,7 @@ /* This file is part of libmicrohttpd - Copyright (C) 2007, 2009 Daniel Pittman and Christian Grothoff + Copyright (C) 2007--2019 Daniel Pittman, Christian Grothoff and + Karlson2k (Evgeny Grin) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -23,6 +24,7 @@ * for each connection and bounding memory use for each * request * @author Christian Grothoff + * @author Karlson2k (Evgeny Grin) */ #ifndef MEMORYPOOL_H