Whether the array_arg is initialized by malloc/new and the integer_arg is the size.
(array_arg: &Node, integer_arg: &Node, visitor: &Visitor)
| 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); |
no test coverage detected