diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2019-06-12 17:18:24 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2019-06-12 17:18:24 +0300 |
commit | 16c9a00cb7dc06ee4ef988f443da7c1ad780b3f6 (patch) | |
tree | 37ff4236fccb2aa368f94f8412a10e682bafed13 | |
parent | d49359450cc6048df6fad758f2078b429dce28d8 (diff) | |
download | libmicrohttpd-16c9a00cb7dc06ee4ef988f443da7c1ad780b3f6.tar.gz libmicrohttpd-16c9a00cb7dc06ee4ef988f443da7c1ad780b3f6.zip |
memorypool.c: added asserts
-rw-r--r-- | src/microhttpd/memorypool.c | 22 | ||||
-rw-r--r-- | src/microhttpd/memorypool.h | 4 |
2 files changed, 24 insertions, 2 deletions
diff --git a/src/microhttpd/memorypool.c b/src/microhttpd/memorypool.c index bda45e1e..9639d552 100644 --- a/src/microhttpd/memorypool.c +++ b/src/microhttpd/memorypool.c | |||
@@ -1,6 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libmicrohttpd | 2 | This file is part of libmicrohttpd |
3 | Copyright (C) 2007, 2009, 2010 Daniel Pittman and Christian Grothoff | 3 | Copyright (C) 2007--2019 Daniel Pittman, Christian Grothoff and |
4 | Karlson2k (Evgeny Grin) | ||
4 | 5 | ||
5 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public | 7 | modify it under the terms of the GNU Lesser General Public |
@@ -21,8 +22,10 @@ | |||
21 | * @file memorypool.c | 22 | * @file memorypool.c |
22 | * @brief memory pool | 23 | * @brief memory pool |
23 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | * @author Karlson2k (Evgeny Grin) | ||
24 | */ | 26 | */ |
25 | #include "memorypool.h" | 27 | #include "memorypool.h" |
28 | #include "mhd_assert.h" | ||
26 | 29 | ||
27 | /* define MAP_ANONYMOUS for Mac OS X */ | 30 | /* define MAP_ANONYMOUS for Mac OS X */ |
28 | #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) | 31 | #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) |
@@ -158,6 +161,9 @@ MHD_pool_destroy (struct MemoryPool *pool) | |||
158 | { | 161 | { |
159 | if (NULL == pool) | 162 | if (NULL == pool) |
160 | return; | 163 | return; |
164 | |||
165 | mhd_assert (pool->end >= pool->pos); | ||
166 | mhd_assert (pool->size >= pool->end - pool->pos); | ||
161 | if (MHD_NO == pool->is_mmap) | 167 | if (MHD_NO == pool->is_mmap) |
162 | free (pool->memory); | 168 | free (pool->memory); |
163 | else | 169 | else |
@@ -184,6 +190,8 @@ MHD_pool_destroy (struct MemoryPool *pool) | |||
184 | size_t | 190 | size_t |
185 | MHD_pool_get_free (struct MemoryPool *pool) | 191 | MHD_pool_get_free (struct MemoryPool *pool) |
186 | { | 192 | { |
193 | mhd_assert (pool->end >= pool->pos); | ||
194 | mhd_assert (pool->size >= pool->end - pool->pos); | ||
187 | return (pool->end - pool->pos); | 195 | return (pool->end - pool->pos); |
188 | } | 196 | } |
189 | 197 | ||
@@ -207,6 +215,8 @@ MHD_pool_allocate (struct MemoryPool *pool, | |||
207 | void *ret; | 215 | void *ret; |
208 | size_t asize; | 216 | size_t asize; |
209 | 217 | ||
218 | mhd_assert (pool->end >= pool->pos); | ||
219 | mhd_assert (pool->size >= pool->end - pool->pos); | ||
210 | asize = ROUND_TO_ALIGN (size); | 220 | asize = ROUND_TO_ALIGN (size); |
211 | if ( (0 == asize) && (0 != size) ) | 221 | if ( (0 == asize) && (0 != size) ) |
212 | return NULL; /* size too close to SIZE_MAX */ | 222 | return NULL; /* size too close to SIZE_MAX */ |
@@ -253,6 +263,11 @@ MHD_pool_reallocate (struct MemoryPool *pool, | |||
253 | void *ret; | 263 | void *ret; |
254 | size_t asize; | 264 | size_t asize; |
255 | 265 | ||
266 | mhd_assert (pool->end >= pool->pos); | ||
267 | mhd_assert (pool->size >= pool->end - pool->pos); | ||
268 | mhd_assert (old != NULL || old_size == 0); | ||
269 | mhd_assert (old == NULL || pool->memory <= (char*)old); | ||
270 | mhd_assert (old == NULL || pool->memory + pool->size >= (char*)old + old_size); | ||
256 | asize = ROUND_TO_ALIGN (new_size); | 271 | asize = ROUND_TO_ALIGN (new_size); |
257 | if ( (0 == asize) && | 272 | if ( (0 == asize) && |
258 | (0 != new_size) ) | 273 | (0 != new_size) ) |
@@ -316,6 +331,11 @@ MHD_pool_reset (struct MemoryPool *pool, | |||
316 | size_t copy_bytes, | 331 | size_t copy_bytes, |
317 | size_t new_size) | 332 | size_t new_size) |
318 | { | 333 | { |
334 | mhd_assert (pool->end >= pool->pos); | ||
335 | mhd_assert (pool->size >= pool->end - pool->pos); | ||
336 | mhd_assert (keep != NULL || copy_bytes == 0); | ||
337 | mhd_assert (keep == NULL || pool->memory <= (char*)keep); | ||
338 | mhd_assert (keep == NULL || pool->memory + pool->size >= (char*)keep + copy_bytes); | ||
319 | if ( (NULL != keep) && | 339 | if ( (NULL != keep) && |
320 | (keep != pool->memory) ) | 340 | (keep != pool->memory) ) |
321 | { | 341 | { |
diff --git a/src/microhttpd/memorypool.h b/src/microhttpd/memorypool.h index 36136af8..69b7e851 100644 --- a/src/microhttpd/memorypool.h +++ b/src/microhttpd/memorypool.h | |||
@@ -1,6 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libmicrohttpd | 2 | This file is part of libmicrohttpd |
3 | Copyright (C) 2007, 2009 Daniel Pittman and Christian Grothoff | 3 | Copyright (C) 2007--2019 Daniel Pittman, Christian Grothoff and |
4 | Karlson2k (Evgeny Grin) | ||
4 | 5 | ||
5 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public | 7 | modify it under the terms of the GNU Lesser General Public |
@@ -23,6 +24,7 @@ | |||
23 | * for each connection and bounding memory use for each | 24 | * for each connection and bounding memory use for each |
24 | * request | 25 | * request |
25 | * @author Christian Grothoff | 26 | * @author Christian Grothoff |
27 | * @author Karlson2k (Evgeny Grin) | ||
26 | */ | 28 | */ |
27 | 29 | ||
28 | #ifndef MEMORYPOOL_H | 30 | #ifndef MEMORYPOOL_H |