From bb5308327173bb48d77a464c879f64c5518fe162 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Tue, 7 Sep 2021 16:13:41 +0800 Subject: [PATCH] [array (rust)] Fix building uncontiguous array --- src/pdata/array_builder.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pdata/array_builder.rs b/src/pdata/array_builder.rs index d19a6bd..bc89f01 100644 --- a/src/pdata/array_builder.rs +++ b/src/pdata/array_builder.rs @@ -59,8 +59,7 @@ impl ArrayBlockBuilder { let bi = index / self.entries_per_block as u64; let i = (index % self.entries_per_block as u64) as usize; - if bi < self.array_blocks.len() as u64 || i < self.values.len() || index >= self.nr_entries - { + if index >= self.nr_entries { return Err(anyhow!("array index out of bounds")); } @@ -68,8 +67,12 @@ impl ArrayBlockBuilder { self.emit_block(w)?; } - if i > self.values.len() + 1 { - self.values.resize_with(i - 1, Default::default); + if bi < self.array_blocks.len() as u64 || i < self.values.len() { + return Err(anyhow!("unordered array index")); + } + + if i > self.values.len() { + self.values.resize_with(i, Default::default); } self.values.push(v);