浏览代码

Prevent overflow in `src/memory_map.rs` (#15)

Cast to u64 before calculating offset
Calvin Lee 8 年之前
父节点
当前提交
94e52a9cec
共有 1 个文件被更改,包括 3 次插入2 次删除
  1. 3 2
      src/memory_map.rs

+ 3 - 2
src/memory_map.rs

@@ -13,7 +13,8 @@ impl MemoryMapTag {
         let start_area = (&self.first_area) as *const MemoryArea;
         MemoryAreaIter {
             current_area: start_area,
-            last_area: ((self_ptr as u32) + self.size - self.entry_size) as *const MemoryArea,
+            last_area: (self_ptr as u64 + (self.size - self.entry_size) as u64)
+                as *const MemoryArea,
             entry_size: self.entry_size,
         }
     }
@@ -41,7 +42,7 @@ impl Iterator for MemoryAreaIter {
             None
         } else {
             let area = unsafe{&*self.current_area};
-            self.current_area = ((self.current_area as u32) + self.entry_size)
+            self.current_area = ((self.current_area as u64) + self.entry_size as u64)
                 as *const MemoryArea;
             if area.typ == 1 {
                 Some(area)