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

Method change_arg_by_constraint

src/program/transform.rs:607–670  ·  view source on GitHub ↗
(
        &mut self,
        call: (&Node, &str, usize),
        arg_pos: usize,
        arg_node: &Node,
        constraint: &Option<Constraint>,
        ty: &str,
        visitor: &Visitor,
    )

Source from the content-addressed store, hash-verified

605 }
606
607 fn change_arg_by_constraint(
608 &mut self,
609 call: (&Node, &str, usize),
610 arg_pos: usize,
611 arg_node: &Node,
612 constraint: &Option<Constraint>,
613 ty: &str,
614 visitor: &Visitor,
615 ) -> Result<()> {
616 let (call_node, call_name, n_call) = call;
617 let arg_node = arg_node.ignore_parenexpr();
618 if is_fuzzable_array_ty(ty) {
619 if let Clang::StringLiteral(_) = &arg_node.kind {
620 self.makeup_call_string_arg(call_node, arg_pos, constraint)?;
621 return Ok(());
622 } else if let Clang::InitListExpr(ile) = &arg_node.kind {
623 if !ile.is_mutable_list(arg_node) {
624 return Ok(());
625 }
626 if is_sized_array_ty(ty) {
627 self.makeup_sized_call_list_arg(ile, call_node, call_name, n_call, arg_pos)?;
628 } else {
629 self.makeup_call_list_arg(
630 ile, call_node, call_name, n_call, arg_pos, constraint,
631 )?;
632 }
633 return Ok(());
634 }
635 }
636
637 if is_integer_ty(ty) {
638 if let Clang::IntegerLiteral(_) = &arg_node.kind {
639 self.makeup_call_integer_arg(call_node, arg_pos, ty)?;
640 return Ok(());
641 } else if let Clang::EnumConstantDecl(ecd) = &arg_node.kind {
642 if ecd.get_const_value(arg_node).is_some() {
643 self.makeup_call_integer_arg(call_node, arg_pos, ty)?;
644 }
645 return Ok(());
646 } else if let Clang::UnaryOperator(uo) = &arg_node.kind {
647 if !uo.is_minus() || arg_node.inner.len() != 1 {
648 return Ok(());
649 }
650 if let Clang::IntegerLiteral(_) = &arg_node.inner[0].kind {
651 self.makeup_call_integer_arg(call_node, arg_pos, ty)?;
652 }
653 return Ok(());
654 }
655 }
656
657 if let Clang::DeclRefExpr(dre) = &arg_node.kind {
658 if let Some(init) = dre.get_var_init(visitor) {
659 self.change_arg_by_constraint(
660 (call_node, call_name, n_call),
661 arg_pos,
662 init,
663 constraint,
664 ty,

Callers 1

Calls 12

is_fuzzable_array_tyFunction · 0.85
is_sized_array_tyFunction · 0.85
is_integer_tyFunction · 0.85
ignore_parenexprMethod · 0.80
is_mutable_listMethod · 0.80
makeup_call_list_argMethod · 0.80
get_const_valueMethod · 0.80
is_minusMethod · 0.80
get_var_initMethod · 0.80

Tested by

no test coverage detected