Skip to content

Commit

Permalink
heap end off by one
Browse files Browse the repository at this point in the history
  • Loading branch information
SciLor committed May 1, 2022
1 parent d719b70 commit 9c0d227
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libraries/Arduino-MemoryFree/MemoryFree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void setCanaries() {
uint32_t *heap_end = (uint32_t*)heapEnd();
uint32_t *heapPtr = (uint32_t*)heapPointer();

heap_end -= 1; //sic!
while(heap_end>heapPtr) {
heap_end[0] = CANARY_HEAP;
heap_end -= 1;
Expand All @@ -65,6 +66,7 @@ bool testStackCanary() {
}
bool testHeapCanary() {
uint32_t *heap_end = (uint32_t*)heapEnd();
heap_end -= 1; //sic!
return (heap_end[0] == CANARY_HEAP);
}

Expand All @@ -83,6 +85,7 @@ uint32_t countHeapCanaries() {
uint32_t canaries = 0;
uint32_t *heapPtr = (uint32_t*)heapPointer();
uint32_t *heap_end = (uint32_t*)heapEnd();
heap_end -= 1; //sic!

while (heap_end[0] == CANARY_HEAP && heap_end > heapPtr) {
canaries++;
Expand Down

0 comments on commit 9c0d227

Please sign in to comment.