gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libmicrohttpd] branch master updated (b9cba520 -> d12ed49f


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] branch master updated (b9cba520 -> d12ed49f)
Date: Thu, 13 Jun 2019 18:18:44 +0200

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from b9cba520 memorypool: removed redundant check, which also fails in case 
shrinking
     new 35d581d0 memorypool: correctly support exotic platform where size of 
pointer is not power of two
     new d12ed49f memorypool: reallocate: more checks for value wrap, small 
optimization

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/microhttpd/memorypool.c | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/src/microhttpd/memorypool.c b/src/microhttpd/memorypool.c
index 12a22f22..3770b8c3 100644
--- a/src/microhttpd/memorypool.c
+++ b/src/microhttpd/memorypool.c
@@ -54,7 +54,7 @@
 /**
  * Round up 'n' to a multiple of ALIGN_SIZE.
  */
-#define ROUND_TO_ALIGN(n) (((n)+(ALIGN_SIZE-1)) & (~(ALIGN_SIZE-1)))
+#define ROUND_TO_ALIGN(n) (((n)+(ALIGN_SIZE-1)) / (ALIGN_SIZE) * (ALIGN_SIZE))
 
 
 /**
@@ -267,29 +267,33 @@ MHD_pool_reallocate (struct MemoryPool *pool,
   /* Blocks "from the end" must not be reallocated */
   mhd_assert (old == NULL || pool->memory + pool->pos > (uint8_t*)old);
 
-  if (new_size + 2 * ALIGN_SIZE < new_size)
-    return NULL; /* Value wrap, too large new_size. */
-
   if (0 != old_size)
-    { /* Need to relocate data */
+    { /* Need to save some data */
       const size_t old_offset = (uint8_t*)old - pool->memory;
-
+      /* Try resizing in-place */
       if (pool->pos == ROUND_TO_ALIGN (old_offset + old_size))
         { /* "old" block is the last allocated block */
           const size_t new_apos = ROUND_TO_ALIGN (old_offset + new_size);
-          if (new_apos > pool->end)
-            return NULL; /* No space */
-
-          pool->pos = new_apos;
-          /* Zero-out unused part if shrinking */
           if (old_size > new_size)
-            memset ((uint8_t*)old + new_size, 0, old_size - new_size);
+            { /* Shrinking in-place, zero-out freed part */
+              memset ((uint8_t*)old + new_size, 0, old_size - new_size);
+            }
+          else
+            { /* Grow in-place, check for enough space. */
+              if ( (new_apos > pool->end) ||
+                   (new_apos < pool->pos) ) /* Value wrap */
+                return NULL; /* No space */
+            }
+          /* Resized in-place */
+          pool->pos = new_apos;
           return old;
         }
     }
   /* Need to allocate new block */
   asize = ROUND_TO_ALIGN (new_size);
-  if (asize > pool->end - pool->pos)
+  if ( ( (0 == asize) &&
+         (0 != new_size) ) || /* Value wrap, too large new_size. */
+       (asize > pool->end - pool->pos) )
     return NULL; /* No space */
 
   new_blc = pool->memory + pool->pos;
@@ -297,9 +301,9 @@ MHD_pool_reallocate (struct MemoryPool *pool,
 
   if (0 != old_size)
     {
-      /* Move data no new block, old block remains allocated */
+      /* Move data to new block, old block remains allocated */
       memcpy (new_blc, old, old_size);
-      /* Zero-out old block */
+      /* Zero-out freed old block */
       memset (old, 0, old_size);
     }
   return new_blc;

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



reply via email to

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