diff --git a/infer/src/clang/cTL.ml b/infer/src/clang/cTL.ml index 9c897fa19..8f0c1ec06 100644 --- a/infer/src/clang/cTL.ml +++ b/infer/src/clang/cTL.ml @@ -842,6 +842,13 @@ let transition_via_specified_parameter ~pos an key = in let apply_decl arg = Decl arg in let apply_stmt arg = Stmt arg in + let compute_nodes parameters = + let parameter_of_corresp_key = + if pos then parameter_of_corresp_pos else invalid_param_name_use () + in + let arg_stmt_opt = parameter_of_corresp_key parameters key in + node_opt_to_ast_node_list apply_stmt arg_stmt_opt + in match an with | Stmt (ObjCMessageExpr (_, stmt_list, _, omei)) -> let method_name = omei.omei_selector in @@ -851,11 +858,9 @@ let transition_via_specified_parameter ~pos an key = let arg_stmt_opt = parameter_of_corresp_key stmt_list key in node_opt_to_ast_node_list apply_stmt arg_stmt_opt | Stmt (CallExpr (_, _ :: args, _)) -> - let parameter_of_corresp_key = - if pos then parameter_of_corresp_pos else invalid_param_name_use () - in - let arg_stmt_opt = parameter_of_corresp_key args key in - node_opt_to_ast_node_list apply_stmt arg_stmt_opt + compute_nodes args + | Stmt (CXXMemberCallExpr (_, stmt_list, _)) -> + compute_nodes stmt_list | Decl (ObjCMethodDecl (_, named_decl_info, omdi)) -> let method_name = named_decl_info.ni_name in let parameter_of_corresp_key = diff --git a/infer/tests/codetoanalyze/objcpp/linters-for-test-only/BadRegexInPointNameForPerfLogging.mm b/infer/tests/codetoanalyze/objcpp/linters-for-test-only/BadRegexInPointNameForPerfLogging.mm new file mode 100644 index 000000000..5d5c0e0c1 --- /dev/null +++ b/infer/tests/codetoanalyze/objcpp/linters-for-test-only/BadRegexInPointNameForPerfLogging.mm @@ -0,0 +1,19 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +#import +#include "One.h" + +@interface BadRegexInPointNameForPerfLogging : NSObject +void testRegexSafe(); +@end + +@implementation BadRegexInPointNameForPerfLogging +void testRegexSafe() { + std::shared_ptr one = std::make_shared(); + one->test(1, "Sample"); +} +@end diff --git a/infer/tests/codetoanalyze/objcpp/linters-for-test-only/One.cpp b/infer/tests/codetoanalyze/objcpp/linters-for-test-only/One.cpp new file mode 100644 index 000000000..035996785 --- /dev/null +++ b/infer/tests/codetoanalyze/objcpp/linters-for-test-only/One.cpp @@ -0,0 +1,13 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +#include "One.h" +#include +void One::test(int markerId, const std::string& name) { + // do nothing +} + +int main() { return 0; } diff --git a/infer/tests/codetoanalyze/objcpp/linters-for-test-only/One.h b/infer/tests/codetoanalyze/objcpp/linters-for-test-only/One.h new file mode 100644 index 000000000..1a310e576 --- /dev/null +++ b/infer/tests/codetoanalyze/objcpp/linters-for-test-only/One.h @@ -0,0 +1,11 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +#include +class One { + public: + void test(int markerId, const std::string& name); +}; diff --git a/infer/tests/codetoanalyze/objcpp/linters-for-test-only/issues.exp b/infer/tests/codetoanalyze/objcpp/linters-for-test-only/issues.exp index 3f38ee4ea..d7d466dd7 100644 --- a/infer/tests/codetoanalyze/objcpp/linters-for-test-only/issues.exp +++ b/infer/tests/codetoanalyze/objcpp/linters-for-test-only/issues.exp @@ -1,3 +1,4 @@ +codetoanalyze/objcpp/linters-for-test-only/BadRegexInPointNameForPerfLogging.mm, testRegexSafe, 17, TEST_PROPERTY_ON_NTH_PARAMETER, no_bucket, WARNING, [] codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest::newWithAction, 25, TEST_REFERENCE, no_bucket, WARNING, [] codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest::newWithAction, 42, TEST_REFERENCE, no_bucket, WARNING, [] codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest::newWithActionRef, 22, TEST_REFERENCE, no_bucket, WARNING, [] diff --git a/infer/tests/codetoanalyze/objcpp/linters-for-test-only/linters_example.al b/infer/tests/codetoanalyze/objcpp/linters-for-test-only/linters_example.al index 4a947ebfb..2dd0edb73 100644 --- a/infer/tests/codetoanalyze/objcpp/linters-for-test-only/linters_example.al +++ b/infer/tests/codetoanalyze/objcpp/linters-for-test-only/linters_example.al @@ -233,3 +233,18 @@ DEFINE-CHECKER ONLY_ONE_CLASS_METHOD = { SET mode = "ON"; }; + +DEFINE-CHECKER TEST_PROPERTY_ON_NTH_PARAMETER = { + + LET check_prop = + WHEN + HOLDS-NEXT WITH-TRANSITION ParameterPos "2" + (has_value("Sample") HOLDS-EVENTUALLY) + HOLDS-IN-NODE CXXMemberCallExpr; + + SET report_when = + call_cxx_method("test") AND check_prop; + + SET message = "The second parameter is the string Sample"; + +};