Skip to content

Commit 2fcb07f

Browse files
gregmeddlukas-he
authored andcommitted
Add empty function checks in CalleeHandle
The CalleeHandle class is the "owner" of the callback function objects associated with a callback connection. As such, it will check the validity of those function objects and throw the EmptyFunctionObject exception if either the callback or cleanup function is empty / invalid.
1 parent d5dbfcf commit 2fcb07f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

include/up-cpp/utils/CallbackConnection.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,21 @@ struct [[nodiscard]] CalleeHandle {
266266
"Attempted to create a connected CalleeHandle with bad "
267267
"connection pointer");
268268
}
269+
269270
if (!callback_) {
270271
throw BadConnection(
271272
"Attempted to create a connected CalleeHandle with bad "
272273
"callback pointer");
273274
}
275+
276+
const auto& callback_obj = *callback_;
277+
if (!callback_obj) {
278+
throw EmptyFunctionObject("Callback function is empty");
279+
}
280+
281+
if (cleanup_ && !cleanup_.value()) {
282+
throw EmptyFunctionObject("Cleanup function is empty");
283+
}
274284
}
275285

276286
/// @brief CalleeHandles can be move constructed

0 commit comments

Comments
 (0)