gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [libmicrohttpd] 01/02: memorypool.c: added asserts


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] 01/02: memorypool.c: added asserts
Date: Wed, 12 Jun 2019 16:39:17 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit 16c9a00cb7dc06ee4ef988f443da7c1ad780b3f6
Author: Evgeny Grin (Karlson2k) <address@hidden>
AuthorDate: Wed Jun 12 17:18:24 2019 +0300

    memorypool.c: added asserts
---
 src/microhttpd/memorypool.c | 22 +++++++++++++++++++++-
 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 @@
 /*
      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
index 36136af8..69b7e851 100644
--- 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

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]