Browse Source

Always set memptr in posix_memalign()

Peter Limkilde Svendsen 4 năm trước cách đây
mục cha
commit
da8d2fa7aa
1 tập tin đã thay đổi với 5 bổ sung4 xóa
  1. 5 4
      src/header/stdlib/mod.rs

+ 5 - 4
src/header/stdlib/mod.rs

@@ -647,13 +647,14 @@ pub unsafe extern "C" fn posix_memalign(
 
     if alignment % VOID_PTR_SIZE == 0 && alignment.is_power_of_two() {
         let ptr = platform::alloc_align(size, alignment);
-        if !ptr.is_null() {
-            *memptr = ptr;
-            0
-        } else {
+        *memptr = ptr;
+        if ptr.is_null() {
             ENOMEM
+        } else {
+            0
         }
     } else {
+        *memptr = ptr::null_mut();
         EINVAL
     }
 }