Module: xenomai-forge
Branch: master
Commit: a10eca3633e847951e4add3a2b8816a113a46606
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=a10eca3633e847951e4add3a2b8816a113a46606

Author: Philippe Gerum <r...@xenomai.org>
Date:   Mon Nov  7 10:15:55 2011 +0100

copperplate/heapobj-pshared: fix minimum size in heap creation

---

 lib/copperplate/heapobj-pshared.c |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/lib/copperplate/heapobj-pshared.c 
b/lib/copperplate/heapobj-pshared.c
index bfc8a4f..6875932 100644
--- a/lib/copperplate/heapobj-pshared.c
+++ b/lib/copperplate/heapobj-pshared.c
@@ -564,13 +564,18 @@ static int create_heap(struct heapobj *hobj, const char 
*session,
        memoff_t len;
        int ret, fd;
 
-       if (size <= sizeof(struct heap_extent))
-               size = sizeof(struct heap_extent);
-       else {
-               size = __align_to(size, HOBJ_PAGE_SIZE);
-               if (size > HOBJ_MAXEXTSZ)
-                       return __bt(-EINVAL);
-       }
+       /*
+        * A storage page should be obviously larger than an extent
+        * header, but we still make sure of this in debug mode, so
+        * that we can rely on __align_to() for rounding to the
+        * minimum size in production builds, without any further
+        * test (e.g. like size >= sizeof(struct heap_extent)).
+        */
+       assert(HOBJ_PAGE_SIZE > sizeof(struct heap_extent));
+
+       size = __align_to(size, HOBJ_PAGE_SIZE);
+       if (size > HOBJ_MAXEXTSZ)
+               return __bt(-EINVAL);
 
        if (size - sizeof(struct heap_extent) < HOBJ_PAGE_SIZE * 2)
                size += HOBJ_PAGE_SIZE * 2;


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to