From 6c6a116b4ad5df283329d666bb0100734eefce8a Mon Sep 17 00:00:00 2001
From: Terraneo Federico <fede.tft@miosix.org>
Date: Wed, 29 Mar 2023 10:04:58 +0200
Subject: [PATCH] More IntrusiveList error checks

---
 miosix/kernel/intrusive.h | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/miosix/kernel/intrusive.h b/miosix/kernel/intrusive.h
index d2800e78..a0690a30 100755
--- a/miosix/kernel/intrusive.h
+++ b/miosix/kernel/intrusive.h
@@ -872,12 +872,26 @@ public:
     /**
      * \return a pointer to the first item. List must not be empty
      */
-    T* front() { return static_cast<T*>(IntrusiveListBase::front()); }
+    T* front()
+    {
+        auto result=IntrusiveListBase::front();
+        #ifdef INTRUSIVE_LIST_ERROR_CHECK
+        if(result==nullptr) fail();
+        #endif //INTRUSIVE_LIST_ERROR_CHECK
+        return static_cast<T*>(result);
+    }
     
     /**
      * \return a pointer to the last item. List must not be empty
      */
-    T* back() { return static_cast<T*>(IntrusiveListBase::back()); }
+    T* back()
+    {
+        auto result=IntrusiveListBase::back();
+        #ifdef INTRUSIVE_LIST_ERROR_CHECK
+        if(result==nullptr) fail();
+        #endif //INTRUSIVE_LIST_ERROR_CHECK
+        return static_cast<T*>(result);
+    }
     
     /**
      * \return true if the list is empty
-- 
GitLab