Skip to content

Commit 43eb824

Browse files
committed
Fix index out of bounds when a partition number is skipped
1 parent 87f5a32 commit 43eb824

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/read/get_partition/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ pub fn parted_list_partition() -> Vec<Disk> {
139139
let x = x.to_vec();
140140
let mut partition = Vec::<Partition>::new();
141141

142+
let mut index = 0;
143+
142144
for part in vec_partition_parted.iter() {
143145
let number: Option<String> = is_available_string(part["number"].to_string());
144146
let start: Option<String> = is_available_string(part["start"].to_string());
@@ -166,11 +168,12 @@ pub fn parted_list_partition() -> Vec<Disk> {
166168

167169
// memasukan tambahan nilai dari lsblk
168170
if number_checker != 0 {
169-
let partition_path = &x[number_checker - 1];
171+
index += 1;
172+
let partition_path = &x[index - 1];
170173
let partition_path =
171174
is_available_string(partition_path["name"].to_string());
172175

173-
let mountpoints = &x[number_checker - 1];
176+
let mountpoints = &x[index - 1];
174177
let mountpoints = is_available_vec(mountpoints["mountpoints"].as_array());
175178

176179
a_partition = Partition::new(

0 commit comments

Comments
 (0)