diff --git a/infer/tests/codetoanalyze/cpp/pulse/frontend.cpp b/infer/tests/codetoanalyze/cpp/pulse/frontend.cpp index 7ef02bfe5..bae143d8b 100644 --- a/infer/tests/codetoanalyze/cpp/pulse/frontend.cpp +++ b/infer/tests/codetoanalyze/cpp/pulse/frontend.cpp @@ -203,4 +203,42 @@ void not_boolean_bad() { } } +struct double_fields_struct { + int v; + int a; +}; + +double_fields_struct get_double_fields_struct() { + double_fields_struct b; + b.v = 42; + b.a = 42; + return b; +} + +void init_double_fields_struct_ok() { + double_fields_struct y{get_double_fields_struct()}; + if (y.v != 42) { + int* p = nullptr; + *p = 42; + } +} + +struct single_field_struct { + int v; +}; + +single_field_struct get_single_field_struct() { + single_field_struct b; + b.v = 42; + return b; +} + +void FP_init_single_field_struct_ok() { + single_field_struct y{get_single_field_struct()}; + if (y.v != 42) { + int* p = nullptr; + *p = 42; + } +} + } // namespace frontend diff --git a/infer/tests/codetoanalyze/cpp/pulse/issues.exp b/infer/tests/codetoanalyze/cpp/pulse/issues.exp index d83d45b4b..e952a1d72 100644 --- a/infer/tests/codetoanalyze/cpp/pulse/issues.exp +++ b/infer/tests/codetoanalyze/cpp/pulse/issues.exp @@ -32,6 +32,7 @@ codetoanalyze/cpp/pulse/deduplication.cpp, deduplication::templated_function_bad codetoanalyze/cpp/pulse/deduplication.cpp, deduplication::templated_function_bad, 3, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,passed as argument to `new` (modelled),return from call to `new` (modelled),assigned,when calling `deduplication::templated_delete_function` here,parameter `a` of deduplication::templated_delete_function,was invalidated by `delete`,use-after-lifetime part of the trace starts here,passed as argument to `new` (modelled),return from call to `new` (modelled),assigned,when calling `deduplication::templated_access_function` here,parameter `a` of deduplication::templated_access_function,invalid access occurs here] codetoanalyze/cpp/pulse/exit_test.cpp, store_exit_null_bad, 0, NULLPTR_DEREFERENCE, no_bucket, ERROR, [invalidation part of the trace starts here,assigned,is the null pointer,use-after-lifetime part of the trace starts here,when calling `store_exit` here,parameter `x` of store_exit,invalid access occurs here] codetoanalyze/cpp/pulse/folly_DestructorGuard.cpp, UsingDelayedDestruction::double_delete_bad, 2, USE_AFTER_DELETE, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `this` of UsingDelayedDestruction::double_delete_bad,was invalidated by `delete`,use-after-lifetime part of the trace starts here,parameter `this` of UsingDelayedDestruction::double_delete_bad,invalid access occurs here] +codetoanalyze/cpp/pulse/frontend.cpp, frontend::FP_init_single_field_struct_ok, 4, NULLPTR_DEREFERENCE, no_bucket, ERROR, [invalidation part of the trace starts here,assigned,is the null pointer,use-after-lifetime part of the trace starts here,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/frontend.cpp, frontend::call_Frontend_constructor2_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [invalidation part of the trace starts here,assigned,is the null pointer,use-after-lifetime part of the trace starts here,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/frontend.cpp, frontend::call_Frontend_constructor_bad, 4, NULLPTR_DEREFERENCE, no_bucket, ERROR, [invalidation part of the trace starts here,assigned,is the null pointer,use-after-lifetime part of the trace starts here,assigned,invalid access occurs here] codetoanalyze/cpp/pulse/frontend.cpp, frontend::call_set_field_via_local_bad, 5, NULLPTR_DEREFERENCE, no_bucket, ERROR, [invalidation part of the trace starts here,assigned,is the null pointer,use-after-lifetime part of the trace starts here,assigned,invalid access occurs here]