MCPcopy Create free account
hub / github.com/FuzzAnything/PromptFuzz / is_alloc_size_of_var

Function is_alloc_size_of_var

src/program/infer/static_infer.rs:650–675  ·  view source on GitHub ↗

Whether the array_arg is initialized by malloc/new and the integer_arg is the size.

(array_arg: &Node, integer_arg: &Node, visitor: &Visitor)

Source from the content-addressed store, hash-verified

648
649 /// Whether the array_arg is initialized by malloc/new and the integer_arg is the size.
650 pub fn is_alloc_size_of_var(array_arg: &Node, integer_arg: &Node, visitor: &Visitor) -> bool {
651 let array_arg = strip_prefix(array_arg);
652 if let Clang::DeclRefExpr(dre) = &array_arg.kind {
653 // if this array_arg is initialized by a call.
654 if let Some(call) = dre.get_var_init_call(visitor) {
655 if let Clang::CallExpr(ce) = &call.kind {
656 let call_name = ce.get_name_as_string(call);
657 // if this array_arg is returned by a malloc
658 if call_name != "malloc" {
659 return false;
660 }
661 let malloc_args = ce.get_childs(call);
662 if malloc_args.is_empty() {
663 return false;
664 }
665 return is_size_of_var(malloc_args[0], integer_arg, visitor);
666 }
667 if let Clang::CXXNewExpr(new_expr) = &call.kind {
668 if let Some(new_arg) = new_expr.get_new_size_var(call) {
669 return is_size_of_var(new_arg, integer_arg, visitor);
670 }
671 }
672 }
673 }
674 false
675 }
676
677 pub fn is_strlen_of_var(array_arg: &Node, integer_arg: &Node, visitor: &Visitor) -> bool {
678 let array_arg = strip_prefix(array_arg);

Callers 1

infer_constraintsFunction · 0.85

Calls 7

strip_prefixFunction · 0.85
is_size_of_varFunction · 0.85
get_var_init_callMethod · 0.80
get_name_as_stringMethod · 0.80
get_new_size_varMethod · 0.80
get_childsMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected