From 9e9bba15bf5d4aa7ec1807be56a43a8e219048ee Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Fri, 13 Sep 2024 14:20:19 +0300 Subject: [PATCH] detect write op in view storage - fix clippy --- .../meta-lib/src/tools/wasm_extractor.rs | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/framework/meta-lib/src/tools/wasm_extractor.rs b/framework/meta-lib/src/tools/wasm_extractor.rs index a348a40e30..4cd80507d4 100644 --- a/framework/meta-lib/src/tools/wasm_extractor.rs +++ b/framework/meta-lib/src/tools/wasm_extractor.rs @@ -75,7 +75,7 @@ fn populate_wasm_info( ei_check = is_ei_valid(&imports, check_ei); }, Payload::DataSection(data_section) => { - allocator_trigger = is_fail_allocator_triggered(&data_section); + allocator_trigger = is_fail_allocator_triggered(data_section.clone()); if is_panic_with_message_triggered(data_section.clone()) { has_panic = WITH_MESSAGE; } else if is_panic_without_message_triggered(data_section) { @@ -99,8 +99,8 @@ fn populate_wasm_info( } } let mut visited: HashSet = HashSet::new(); - for (index, _name) in &views_data { - mark_write(*index, &call_graph, &mut write_functions, &mut visited); + for key in views_data.keys() { + mark_write(*key, &call_graph, &mut write_functions, &mut visited); } for (index, name) in views_data { @@ -133,7 +133,7 @@ fn populate_wasm_info( fn parse_export_section( export_section: ExportSectionReader, - view_endpoints: &Vec, + view_endpoints: &[String], ) -> HashMap { let mut views_data: HashMap = HashMap::new(); for export in export_section { @@ -181,20 +181,17 @@ fn create_call_graph(body: FunctionBody, call_graph: &mut HashMap { - let function_usize: usize = function_index.try_into().unwrap(); - call_functions.push(function_usize); - }, - _ => (), + if let Operator::Call { function_index } = op { + let function_usize: usize = function_index.try_into().unwrap(); + call_functions.push(function_usize); } } call_graph.insert(call_graph.len(), call_functions); } -fn is_fail_allocator_triggered(data_section: &DataSectionReader) -> bool { - for data_fragment in data_section.clone().into_iter().flatten() { +fn is_fail_allocator_triggered(data_section: DataSectionReader) -> bool { + for data_fragment in data_section.into_iter().flatten() { if data_fragment .data .windows(ERROR_FAIL_ALLOCATOR.len()) @@ -266,7 +263,7 @@ pub fn extract_imports( import_names } -fn is_ei_valid(imports: &Vec, check_ei: &Option) -> bool { +fn is_ei_valid(imports: &[String], check_ei: &Option) -> bool { if let Some(ei) = check_ei { let mut num_errors = 0; for import in imports {