From cacced7e507f7603bacc03ae2616e58f0ede122a Mon Sep 17 00:00:00 2001 From: Hein-Pieter van Braam Date: Thu, 24 Aug 2017 22:58:51 +0200 Subject: Convert Object::cast_to() to the static version Currently we rely on some undefined behavior when Object->cast_to() gets called with a Null pointer. This used to work fine with GCC < 6 but newer versions of GCC remove all codepaths in which the this pointer is Null. However, the non-static cast_to() was supposed to be null safe. This patch makes cast_to() Null safe and removes the now redundant Null checks where they existed. It is explained in this article: https://www.viva64.com/en/b/0226/ --- editor/plugins/texture_editor_plugin.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'editor/plugins/texture_editor_plugin.cpp') diff --git a/editor/plugins/texture_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp index 57c27a8a7..5648ee510 100644 --- a/editor/plugins/texture_editor_plugin.cpp +++ b/editor/plugins/texture_editor_plugin.cpp @@ -70,7 +70,7 @@ void TextureEditor::_notification(int p_what) { int ofs_x = (size.width - tex_width) / 2; int ofs_y = (size.height - tex_height) / 2; - if (texture->cast_to()) { + if (Object::cast_to(*texture)) { // In the case of CurveTextures we know they are 1 in height, so fill the preview to see the gradient ofs_y = 0; tex_height = size.height; @@ -81,10 +81,10 @@ void TextureEditor::_notification(int p_what) { Ref font = get_font("font", "Label"); String format; - if (texture->cast_to()) { - format = Image::get_format_name(texture->cast_to()->get_format()); - } else if (texture->cast_to()) { - format = Image::get_format_name(texture->cast_to()->get_format()); + if (Object::cast_to(*texture)) { + format = Image::get_format_name(Object::cast_to(*texture)->get_format()); + } else if (Object::cast_to(*texture)) { + format = Image::get_format_name(Object::cast_to(*texture)->get_format()); } else { format = texture->get_class(); } @@ -136,7 +136,7 @@ TextureEditor::TextureEditor() { void TextureEditorPlugin::edit(Object *p_object) { - Texture *s = p_object->cast_to(); + Texture *s = Object::cast_to(p_object); if (!s) return; -- cgit v1.2.3-70-g09d2