Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-12-SP2:GA
libmicrohttpd
bsc854443-part4.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File bsc854443-part4.patch of Package libmicrohttpd
From ba6b6cad9a70cef22f62d5b76cb1180b2aca4e94 Mon Sep 17 00:00:00 2001 From: Christian Grothoff <christian@grothoff.org> Date: Thu, 28 Nov 2013 10:05:52 +0000 Subject: -handle case that original allocation request was zero diff --git a/src/microhttpd/memorypool.c b/src/microhttpd/memorypool.c index f011532..57962c1 100644 --- a/src/microhttpd/memorypool.c +++ b/src/microhttpd/memorypool.c @@ -155,21 +155,22 @@ MHD_pool_allocate (struct MemoryPool *pool, size_t size, int from_end) { void *ret; + size_t asize; - size = ROUND_TO_ALIGN (size); - if (0 == size) + asize = ROUND_TO_ALIGN (size); + if ( (0 == asize) && (0 != size) ) return NULL; /* size too close to SIZE_MAX */ - if ((pool->pos + size > pool->end) || (pool->pos + size < pool->pos)) + if ((pool->pos + asize > pool->end) || (pool->pos + asize < pool->pos)) return NULL; if (from_end == MHD_YES) { - ret = &pool->memory[pool->end - size]; - pool->end -= size; + ret = &pool->memory[pool->end - asize]; + pool->end -= asize; } else { ret = &pool->memory[pool->pos]; - pool->pos += size; + pool->pos += asize; } return ret; } @@ -199,36 +200,37 @@ MHD_pool_reallocate (struct MemoryPool *pool, size_t new_size) { void *ret; + size_t asize; - new_size = ROUND_TO_ALIGN (new_size); - if (0 == new_size) - return NULL; /* size too close to SIZE_MAX */ - if ((pool->end < old_size) || (pool->end < new_size)) + asize = ROUND_TO_ALIGN (new_size); + if ( (0 == asize) && (0 != new_size) ) + return NULL; /* new_size too close to SIZE_MAX */ + if ((pool->end < old_size) || (pool->end < asize)) return NULL; /* unsatisfiable or bogus request */ if ((pool->pos >= old_size) && (&pool->memory[pool->pos - old_size] == old)) { /* was the previous allocation - optimize! */ - if (pool->pos + new_size - old_size <= pool->end) + if (pool->pos + asize - old_size <= pool->end) { /* fits */ - pool->pos += new_size - old_size; - if (new_size < old_size) /* shrinking - zero again! */ - memset (&pool->memory[pool->pos], 0, old_size - new_size); + pool->pos += asize - old_size; + if (asize < old_size) /* shrinking - zero again! */ + memset (&pool->memory[pool->pos], 0, old_size - asize); return old; } /* does not fit */ return NULL; } - if (new_size <= old_size) + if (asize <= old_size) return old; /* cannot shrink, no need to move */ - if ((pool->pos + new_size >= pool->pos) && - (pool->pos + new_size <= pool->end)) + if ((pool->pos + asize >= pool->pos) && + (pool->pos + asize <= pool->end)) { /* fits */ ret = &pool->memory[pool->pos]; memcpy (ret, old, old_size); - pool->pos += new_size; + pool->pos += asize; return ret; } /* does not fit */ -- cgit v0.10.2
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor