MCPcopy Create free account
hub / github.com/diem/move / check_function_def

Method check_function_def

language/move-binary-format/src/check_bounds.rs:308–344  ·  view source on GitHub ↗
(
        &mut self,
        function_def_idx: usize,
        function_def: &FunctionDefinition,
    )

Source from the content-addressed store, hash-verified

306 }
307
308 fn check_function_def(
309 &mut self,
310 function_def_idx: usize,
311 function_def: &FunctionDefinition,
312 ) -> PartialVMResult<()> {
313 self.context = BoundsCheckingContext::ModuleFunction(FunctionDefinitionIndex(
314 function_def_idx as TableIndex,
315 ));
316 check_bounds_impl(self.view.function_handles(), function_def.function)?;
317 for ty in &function_def.acquires_global_resources {
318 check_bounds_impl_opt(&self.view.struct_defs(), *ty)?;
319 }
320
321 let code_unit = match &function_def.code {
322 Some(code) => code,
323 None => return Ok(()),
324 };
325
326 debug_assert!(function_def.function.into_index() < self.view.function_handles().len());
327 let function_handle = &self.view.function_handles()[function_def.function.into_index()];
328
329 debug_assert!(function_handle.parameters.into_index() < self.view.signatures().len());
330 let parameters = &self.view.signatures()[function_handle.parameters.into_index()];
331
332 // check if the number of parameters + locals is less than u8::MAX
333 let locals_count = self.get_locals(code_unit)?.len() + parameters.len();
334
335 if locals_count > (u8::MAX as usize) + 1 {
336 return Err(verification_error(
337 StatusCode::TOO_MANY_LOCALS,
338 IndexKind::FunctionDefinition,
339 function_def_idx as TableIndex,
340 ));
341 }
342
343 self.check_code(code_unit, &function_handle.type_parameters, parameters)
344 }
345
346 fn check_code(
347 &self,

Callers 1

check_function_defsMethod · 0.80

Calls 9

check_bounds_implFunction · 0.85
check_bounds_impl_optFunction · 0.85
verification_errorFunction · 0.85
check_codeMethod · 0.80
function_handlesMethod · 0.45
struct_defsMethod · 0.45
signaturesMethod · 0.45
lenMethod · 0.45
get_localsMethod · 0.45

Tested by

no test coverage detected