File tree Expand file tree Collapse file tree 2 files changed +36
-5
lines changed
cpp/ql/test/query-tests/Security/CWE/CWE-570 Expand file tree Collapse file tree 2 files changed +36
-5
lines changed Original file line number Diff line number Diff line change 1313| test.cpp:92:5:92:31 | new[] | This allocation cannot throw. $@ is unnecessary. | test.cpp:97:36:98:3 | { ... } | This catch block |
1414| test.cpp:93:15:93:41 | new[] | This allocation cannot throw. $@ is unnecessary. | test.cpp:97:36:98:3 | { ... } | This catch block |
1515| test.cpp:96:10:96:36 | new[] | This allocation cannot throw. $@ is unnecessary. | test.cpp:97:36:98:3 | { ... } | This catch block |
16- | test.cpp:151:9:151:24 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:152:15:152:18 | { ... } | This catch block |
17- | test.cpp:199:15:199:35 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:201:16:201:19 | { ... } | This catch block |
18- | test.cpp:212:14:212:34 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:213:34:213:36 | { ... } | This catch block |
19- | test.cpp:246:17:246:31 | new[] | This allocation cannot return null. $@ is unnecessary. | test.cpp:247:8:247:12 | ! ... | This check |
16+ | test.cpp:160:9:160:24 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:161:15:161:18 | { ... } | This catch block |
17+ | test.cpp:178:12:178:25 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:179:17:181:3 | { ... } | This catch block |
18+ | test.cpp:229:15:229:35 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:231:16:231:19 | { ... } | This catch block |
19+ | test.cpp:242:14:242:34 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:243:34:243:36 | { ... } | This catch block |
20+ | test.cpp:276:17:276:31 | new[] | This allocation cannot return null. $@ is unnecessary. | test.cpp:277:8:277:12 | ! ... | This check |
Original file line number Diff line number Diff line change @@ -136,6 +136,8 @@ void good_new_handles_nullptr() {
136136 return ; // GOOD
137137}
138138
139+ // ---
140+
139141void * operator new (std::size_t count, void *) noexcept ;
140142void * operator new [](std::size_t count, void *) noexcept ;
141143
@@ -146,18 +148,46 @@ struct Foo {
146148 operator bool ();
147149};
148150
151+ struct Bar {
152+ Bar ();
153+
154+ operator bool ();
155+ };
156+
149157void bad_placement_new_with_exception_handling () {
150158 char buffer[1024 ];
151- try { new (buffer) Foo; } // BAD
159+
160+ try { new (buffer) Foo; } // BAD (placement new should not fail)
152161 catch (...) { }
153162}
154163
155164void good_placement_new_with_exception_handling () {
156165 char buffer[1024 ];
166+
157167 try { new (buffer) Foo (42 ); } // GOOD: Foo constructor might throw
158168 catch (...) { }
169+
170+ try { new (buffer) Bar; } // GOOD: Bar constructor might throw
171+ catch (...) { }
159172}
160173
174+ template <typename F> F *test_template_platement_new () {
175+ char buffer[1024 ];
176+
177+ try {
178+ return new (buffer) F; // GOOD: `F` constructor might throw (when `F` is `Foo`) [FALSE POSITIVE]
179+ } catch (...) {
180+ return 0 ;
181+ }
182+ }
183+
184+ void test_template_platement_new_caller () {
185+ test_template_platement_new<Foo>();
186+ test_template_platement_new<Bar>();
187+ }
188+
189+ // ---
190+
161191int unknown_value_without_exceptions () noexcept ;
162192
163193void may_throw () {
You can’t perform that action at this time.
0 commit comments