Selaa lähdekoodia

Merge branch 'assert-checks'

greatbridf 2 vuotta sitten
vanhempi
commit
c0271b312e
4 muutettua tiedostoa jossa 27 lisäystä ja 23 poistoa
  1. 13 11
      include/types/buffer.hpp
  2. 3 9
      include/types/string.hpp
  3. 3 2
      include/types/vector.hpp
  4. 8 1
      src/types/elf.cpp

+ 13 - 11
include/types/buffer.hpp

@@ -1,6 +1,7 @@
 #pragma once
 
 #include <stdint.h>
+#include <stdio.h>
 #include <types/allocator.hpp>
 
 namespace types {
@@ -90,43 +91,44 @@ public:
         return count == static_cast<size_t>(end - start + 1);
     }
 
-    constexpr char front(void)
+    constexpr int front(void)
     {
+        if (empty())
+            return EOF;
         return *base;
     }
 
-    constexpr char back(void)
+    constexpr int back(void)
     {
+        if (empty())
+            return EOF;
         return *_backward(head);
     }
 
-    constexpr char get(void)
+    constexpr int get(void)
     {
-        // TODO: set error flag
         if (empty())
-            return 0xff;
+            return EOF;
 
         char c = _get_char(base);
         base = _forward(base);
         return c;
     }
 
-    constexpr char pop(void)
+    constexpr int pop(void)
     {
-        // TODO: set error flag
         if (empty())
-            return 0xff;
+            return EOF;
 
         char c = _get_char(_backward(head));
         head = _backward(head);
         return c;
     }
 
-    constexpr char put(char c)
+    constexpr int put(char c)
     {
-        // TODO: set error flag
         if (full())
-            return 0xff;
+            return EOF;
 
         _put_char(c);
         head = _forward(head);

+ 3 - 9
include/types/string.hpp

@@ -91,23 +91,17 @@ public:
     }
     constexpr typename inner_vector_type::iterator_type back(void)
     {
-        // TODO: assert
-        if (this->empty())
-            return typename inner_vector_type::iterator_type((void*)0xffffffff);
+        assert(!this->empty());
         return --inner_vector_type::back();
     }
     constexpr typename inner_vector_type::const_iterator_type back(void) const
     {
-        // TODO: assert
-        if (this->empty())
-            return typename inner_vector_type::iterator_type((void*)0xffffffff);
+        assert(!this->empty());
         return --inner_vector_type::back();
     }
     constexpr typename inner_vector_type::const_iterator_type cback(void) const
     {
-        // TODO: assert
-        if (this->empty())
-            return typename inner_vector_type::iterator_type((void*)0xffffffff);
+        assert(!this->empty());
         return --inner_vector_type::cback();
     }
 };

+ 3 - 2
include/types/vector.hpp

@@ -1,5 +1,6 @@
 #pragma once
 
+#include <assert.h>
 #include <types/allocator.hpp>
 #include <types/cplusplus.hpp>
 #include <types/types.h>
@@ -230,13 +231,13 @@ public:
 
     constexpr value_type& at(index_type i) noexcept
     {
-        // TODO: boundary check
+        assert(i + 1 <= this->size());
         return _at(i);
     }
 
     constexpr const value_type& at(index_type i) const noexcept
     {
-        // TODO: boundary check
+        assert(i + 1 <= this->size());
         return _at(i);
     }
 

+ 8 - 1
src/types/elf.cpp

@@ -1,6 +1,7 @@
 #include <assert.h>
 #include <kernel/errno.h>
 #include <kernel/mem.h>
+#include <kernel/process.hpp>
 #include <kernel/vfs.hpp>
 #include <stdint.h>
 #include <stdio.h>
@@ -78,7 +79,13 @@ int types::elf::elf32_load(types::elf::elf32_load_data* d)
         if (phents[i].type != types::elf::elf32_program_header_entry::PT_LOAD)
             continue;
 
-        auto ret = mmap((void*)phents[i].vaddr, phents[i].filesz, ent_exec->ind, phents[i].offset, 1, d->system);
+        auto ret = mmap(
+            (char*)phents[i].vaddr,
+            phents[i].filesz,
+            ent_exec->ind,
+            phents[i].offset,
+            1,
+            d->system);
 
         if (ret != GB_OK)
             goto error;