Procházet zdrojové kódy

Ensure we clear the entire new mapping/sparse array entry

Previously, only up to the nearest 8 bytes was cleared, so any bytes
beyond that could contain garbage.

Signed-off-by: Sean Young <sean@mess.org>
Sean Young před 4 roky
rodič
revize
c71d85a84a
1 změnil soubory, kde provedl 7 přidání a 2 odebrání
  1. 7 2
      src/emit/solana.rs

+ 7 - 2
src/emit/solana.rs

@@ -796,9 +796,14 @@ impl SolanaTarget {
 
         let member = unsafe { contract.builder.build_gep(data, &[offset], "data") };
 
-        // clear memory
+        // Clear memory. The length argument to __bzero8 is in lengths of 8 bytes. We round up to the nearest
+        // 8 byte, since account_data_alloc also rounds up to the nearest 8 byte when allocating.
         let length = contract.builder.build_int_unsigned_div(
-            entry_length,
+            contract.builder.build_int_add(
+                entry_length,
+                contract.context.i32_type().const_int(7, false),
+                "",
+            ),
             contract.context.i32_type().const_int(8, false),
             "length_div_8",
         );