Skip to content

Commit

Permalink
Fix NULL dereferencing in get_from_variant and cast_to
Browse files Browse the repository at this point in the history
  • Loading branch information
bruvzg committed Nov 26, 2018
1 parent 5225ab2 commit be5a012
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion binding_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def generate_class_header(used_classes, c):
# ___get_class_name
source.append("\tstatic inline const char *___get_class_name() { return (const char *) \"" + strip_name(c["name"]) + "\"; }")

source.append("\tstatic inline Object *___get_from_variant(Variant a) { godot_object *o = (godot_object*) a; return (Object *) godot::nativescript_1_1_api->godot_nativescript_get_instance_binding_data(godot::_RegisterState::language_index, o); }")
source.append("\tstatic inline Object *___get_from_variant(Variant a) { godot_object *o = (godot_object*) a; return (o) ? (Object *) godot::nativescript_1_1_api->godot_nativescript_get_instance_binding_data(godot::_RegisterState::language_index, o) : nullptr; }")

enum_values = []

Expand Down
5 changes: 4 additions & 1 deletion include/core/Godot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace godot {

template <class T>
T *as(const Object *obj) {
return (T *)godot::nativescript_api->godot_nativescript_get_userdata(obj->_owner);
return (obj) ? (T *)godot::nativescript_api->godot_nativescript_get_userdata(obj->_owner) : nullptr;
}

template <class T>
Expand Down Expand Up @@ -428,6 +428,9 @@ void register_signal(String name, Args... varargs) {
#ifndef GODOT_CPP_NO_OBJECT_CAST
template <class T>
T *Object::cast_to(const Object *obj) {
if (!obj)
return nullptr;

size_t have_tag = (size_t)godot::nativescript_1_1_api->godot_nativescript_get_type_tag(obj->_owner);

if (have_tag) {
Expand Down

0 comments on commit be5a012

Please sign in to comment.