summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorA Thousand Ships <96648715+AThousandShips@users.noreply.github.com>2024-04-27 11:56:39 +0200
committerA Thousand Ships <96648715+AThousandShips@users.noreply.github.com>2024-04-27 16:22:57 +0200
commit31e7ee63f21e7b86d41cdb724824d4dc0804f281 (patch)
treecd7146d05bd3ac5069083a1ca499f6662c4971b5 /core
parent6118592c6d88350d01f74faff6fd49754f84a7d0 (diff)
downloadredot-engine-31e7ee63f21e7b86d41cdb724824d4dc0804f281.tar.gz
Fix unsafe uses of `Callable.is_null()`
`Callable.is_null()` is not equivalent to `!Callable.is_valid()` and doesn't guarantee the call is valid.
Diffstat (limited to 'core')
-rw-r--r--core/core_bind.cpp2
-rw-r--r--core/object/object.cpp4
-rw-r--r--core/object/undo_redo.cpp4
3 files changed, 5 insertions, 5 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index 467b696eae..0996db9d89 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -1921,7 +1921,7 @@ void EngineDebugger::send_message(const String &p_msg, const Array &p_data) {
Error EngineDebugger::call_capture(void *p_user, const String &p_cmd, const Array &p_data, bool &r_captured) {
Callable &capture = *(Callable *)p_user;
- if (capture.is_null()) {
+ if (!capture.is_valid()) {
return FAILED;
}
Variant cmd = p_cmd, data = p_data;
diff --git a/core/object/object.cpp b/core/object/object.cpp
index f8d2feb5a8..30629ba205 100644
--- a/core/object/object.cpp
+++ b/core/object/object.cpp
@@ -1455,7 +1455,7 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, ui
}
bool Object::is_connected(const StringName &p_signal, const Callable &p_callable) const {
- ERR_FAIL_COND_V_MSG(p_callable.is_null(), false, "Cannot determine if connected to '" + p_signal + "': the provided callable is null.");
+ ERR_FAIL_COND_V_MSG(p_callable.is_null(), false, "Cannot determine if connected to '" + p_signal + "': the provided callable is null."); // Should use `is_null`, see note in `connect` about the use of `is_valid`.
const SignalData *s = signal_map.getptr(p_signal);
if (!s) {
bool signal_is_valid = ClassDB::has_signal(get_class_name(), p_signal);
@@ -1478,7 +1478,7 @@ void Object::disconnect(const StringName &p_signal, const Callable &p_callable)
}
bool Object::_disconnect(const StringName &p_signal, const Callable &p_callable, bool p_force) {
- ERR_FAIL_COND_V_MSG(p_callable.is_null(), false, "Cannot disconnect from '" + p_signal + "': the provided callable is null.");
+ ERR_FAIL_COND_V_MSG(p_callable.is_null(), false, "Cannot disconnect from '" + p_signal + "': the provided callable is null."); // Should use `is_null`, see note in `connect` about the use of `is_valid`.
SignalData *s = signal_map.getptr(p_signal);
if (!s) {
diff --git a/core/object/undo_redo.cpp b/core/object/undo_redo.cpp
index 6a1385e268..4d67cd930e 100644
--- a/core/object/undo_redo.cpp
+++ b/core/object/undo_redo.cpp
@@ -144,7 +144,7 @@ void UndoRedo::create_action(const String &p_name, MergeMode p_mode, bool p_back
}
void UndoRedo::add_do_method(const Callable &p_callable) {
- ERR_FAIL_COND(p_callable.is_null());
+ ERR_FAIL_COND(!p_callable.is_valid());
ERR_FAIL_COND(action_level <= 0);
ERR_FAIL_COND((current_action + 1) >= actions.size());
@@ -169,7 +169,7 @@ void UndoRedo::add_do_method(const Callable &p_callable) {
}
void UndoRedo::add_undo_method(const Callable &p_callable) {
- ERR_FAIL_COND(p_callable.is_null());
+ ERR_FAIL_COND(!p_callable.is_valid());
ERR_FAIL_COND(action_level <= 0);
ERR_FAIL_COND((current_action + 1) >= actions.size());