shithub: leaf

Download patch

ref: 17acc7ebe11380c9ad4ad92e8e005ec6d1d2a062
parent: 1bf0296869c7184e538b0f602e19a2f3fff735ed
author: Matthew Wang <mjw7@princeton.edu>
date: Wed Jun 17 13:53:55 EDT 2020

add error case to mpool_free

--- a/leaf/Src/leaf-mempool.c
+++ b/leaf/Src/leaf-mempool.c
@@ -261,6 +261,12 @@
     mpool_node_t* next_node;
     while (other_node != NULL)
     {
+        if ((char*)other_node < (char*)pool->head ||
+            (char*)other_node >= ((char*)pool->head + pool->msize))
+        {
+            LEAF_error(2);
+            return;
+        }
         next_node = other_node->next;
         // Check if a node is directly after the freed node
         if ((long) freed_node + (leaf.header_size + freed_node->size) == (long) other_node)
--- a/leaf/Src/leaf.c
+++ b/leaf/Src/leaf.c
@@ -54,7 +54,8 @@
 
 
 //implement a function called this in your user code to catch errors
-__attribute__((weak)) uint8_t LEAF_error(uint8_t whichone)
+//__attribute__((weak))
+uint8_t LEAF_error(uint8_t whichone)
 {
     return whichone;
 }
--- a/leaf/leaf.h
+++ b/leaf/leaf.h
@@ -140,7 +140,8 @@
     float       LEAF_getSampleRate   (void);
     
 
-    __attribute__((weak)) uint8_t LEAF_error(uint8_t whichone);
+//    __attribute__((weak))
+    uint8_t LEAF_error(uint8_t whichone);
     
     /*!
      * @}