aboutsummaryrefslogtreecommitdiffstats
path: root/os/common
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2016-04-17 12:34:55 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2016-04-17 12:34:55 +0000
commit3e783756697b6d62144dd21eb0f052f4759de3e4 (patch)
treeb0e497bf34e562fea971710575e4245a0e876895 /os/common
parentcf607ab30b30a7575f76c2f18814bec8954d6fc9 (diff)
downloadChibiOS-3e783756697b6d62144dd21eb0f052f4759de3e4.tar.gz
ChibiOS-3e783756697b6d62144dd21eb0f052f4759de3e4.tar.bz2
ChibiOS-3e783756697b6d62144dd21eb0f052f4759de3e4.zip
Fixes to the heap allocator.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9304 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/common')
-rw-r--r--os/common/oslib/src/chheap.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/os/common/oslib/src/chheap.c b/os/common/oslib/src/chheap.c
index 91d41864a..f95fbfe1f 100644
--- a/os/common/oslib/src/chheap.c
+++ b/os/common/oslib/src/chheap.c
@@ -196,7 +196,7 @@ void *chHeapAllocAligned(memory_heap_t *heapp, size_t size, unsigned align) {
/* Pointer aligned to the requested alignment.*/
ahp = (heap_header_t *)MEM_ALIGN_NEXT(H_BLOCK(hp), align) - 1U;
- if ((ahp < H_LIMIT(hp)) && (pages <= NPAGES(H_LIMIT(hp), ahp - 1U))) {
+ if ((ahp < H_LIMIT(hp)) && (pages <= NPAGES(H_LIMIT(hp), ahp + 1U))) {
/* The block is large enough to contain a correctly aligned area
of sufficient size.*/
@@ -212,7 +212,7 @@ void *chHeapAllocAligned(memory_heap_t *heapp, size_t size, unsigned align) {
/* Creating the excess block.*/
fp = H_BLOCK(ahp) + pages;
- H_PAGES(fp) = NPAGES(bpages, pages - 1U);
+ H_PAGES(fp) = (bpages - pages) - 1U;
/* Linking the excess block.*/
H_NEXT(fp) = H_NEXT(hp);