Skip to contentSkip to conversation

Mini-OS: use BUG() instead of dereferencing NULL

PATCH In review Juergen Gross 2 participants 2 messages Dec 6, 2023 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Mini-OS: use BUG() instead of dereferencing NULL

There are some places using a dereference of NULL to cause a crash.

Use BUG() instead.

---
 lib/xmalloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/xmalloc.c +2 -2
index cc5db11e..2aa07138 100644
@@ -219,7 +219,7 @@ void xfree(const void *p)
     if(((long)p & PAGE_MASK) != ((long)hdr & PAGE_MASK))
     {
         printk("Header should be on the same page\n");
-        *(int*)0=0;
+        BUG();
     }
 
     /* Merge with other free block, or put in list. */
@@ -255,7 +255,7 @@ void xfree(const void *p)
         if((((unsigned long)hdr) & (PAGE_SIZE-1)) != 0)
         {
             printk("Bug\n");
-            *(int*)0=0;
+            BUG();
         }
         free_page(hdr);
     }
Signature · 1 line
2.35.3
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Juergen Gross

There are some places using a dereference of NULL to cause a crash.

Use BUG() instead.

Wow...

Quoted 26 lines
---
 lib/xmalloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/xmalloc.c +2 -2
index cc5db11e..2aa07138 100644
@@ -219,7 +219,7 @@ void xfree(const void *p)
     if(((long)p & PAGE_MASK) != ((long)hdr & PAGE_MASK))
     {
         printk("Header should be on the same page\n");
-        *(int*)0=0;
+        BUG();
     }
 
     /* Merge with other free block, or put in list. */
@@ -255,7 +255,7 @@ void xfree(const void *p)
         if((((unsigned long)hdr) & (PAGE_SIZE-1)) != 0)
         {
             printk("Bug\n");
-            *(int*)0=0;
+            BUG();
         }
         free_page(hdr);
     }