]> git.xonotic.org Git - xonotic/netradiant.git/commitdiff
Hack around segfault at launch, patch from danfe: https://github.com/TTimo/GtkRadiant...
authorEric Wasylishen <ewasylishen@gmail.com>
Wed, 27 May 2015 06:19:11 +0000 (00:19 -0600)
committerEric Wasylishen <ewasylishen@gmail.com>
Wed, 27 May 2015 06:19:11 +0000 (00:19 -0600)
radiant/treemodel.cpp

index 4d2f82384d8e62415ca44f9ac41644701bf063d6..d36e492a753077eeba8e26cfe67f526d7bb0f58a 100644 (file)
@@ -647,7 +647,13 @@ void detach( const NameCallback& callback ){
 };
 
 void node_attach_name_changed_callback( scene::Node& node, const NameCallback& callback ){
-       if ( &node != 0 ) {
+       // Reference cannot be bound to dereferenced null pointer in well-defined
+       // C++ code, and Clang will assume that comparison below always evaluates
+       // to true, resulting in a segmentation fault.  Use a dirty hack to force
+       // Clang to check those "bad" references for null nonetheless.
+       volatile intptr_t n = (intptr_t)&node;
+
+       if ( n != 0 ) {
                Nameable* nameable = Node_getNameable( node );
                if ( nameable != 0 ) {
                        nameable->attach( callback );
@@ -655,7 +661,9 @@ void node_attach_name_changed_callback( scene::Node& node, const NameCallback& c
        }
 }
 void node_detach_name_changed_callback( scene::Node& node, const NameCallback& callback ){
-       if ( &node != 0 ) {
+       volatile intptr_t n = (intptr_t)&node;  // see the comment on line 650
+
+       if ( n != 0 ) {
                Nameable* nameable = Node_getNameable( node );
                if ( nameable != 0 ) {
                        nameable->detach( callback );
@@ -1124,7 +1132,8 @@ void graph_tree_model_row_deleted( GraphTreeModel& model, GraphTreeNode::iterato
 const char* node_get_name( scene::Node& node );
 
 const char* node_get_name_safe( scene::Node& node ){
-       if ( &node == 0 ) {
+       volatile intptr_t n = (intptr_t)&node;  // see the comment on line 650
+       if ( n == 0 ) {
                return "";
        }
        return node_get_name( node );
@@ -1142,7 +1151,8 @@ GraphTreeNode* graph_tree_model_find_parent( GraphTreeModel* model, const scene:
 }
 
 void node_attach_name_changed_callback( scene::Node& node, const NameCallback& callback ){
-       if ( &node != 0 ) {
+       volatile intptr_t n = (intptr_t)&node;  // see the comment on line 650
+       if ( n != 0 ) {
                Nameable* nameable = Node_getNameable( node );
                if ( nameable != 0 ) {
                        nameable->attach( callback );
@@ -1150,7 +1160,8 @@ void node_attach_name_changed_callback( scene::Node& node, const NameCallback& c
        }
 }
 void node_detach_name_changed_callback( scene::Node& node, const NameCallback& callback ){
-       if ( &node != 0 ) {
+       volatile intptr_t n = (intptr_t)&node;  // see the comment on line 650
+       if ( n != 0 ) {
                Nameable* nameable = Node_getNameable( node );
                if ( nameable != 0 ) {
                        nameable->detach( callback );