Ticket #158 (closed bug report: fixed)

Opened 18 months ago

Last modified 18 months ago

osm2pgrouting segfault if nd node references undefined node

Reported by: paul Owned by: somebody
Priority: major Milestone: Version 1.1
Component: osm2pgrouting Version: trunk
Keywords: segfault, node Cc:

Description

* When a "nd" xml document node is found the sax parser tries to increase a usage counter within the corresponding Node object. * The Node is only created when a "Node" xml Element is parsed.

These conditions lead to a segfault when a nd reference appears for a Node which either does not exist or is declared after the ND reference (is this allowed ?)

The following svn diff shows the changes needed to avoid segfault

Index: src/OSMDocumentParserCallback.cpp
===================================================================
--- src/OSMDocumentParserCallback.cpp   (revision 331)
+++ src/OSMDocumentParserCallback.cpp   (working copy)
@@ -46,8 +46,14 @@
                        if( strcmp(name,"ref")==0 )
                        {
                                long long nodeRefId = atol( value );
-                               m_pActWay->AddNodeRef( m_rDocument.FindNode( nodeRefId ) );
-                               m_rDocument.FindNode( nodeRefId )->numsOfUse+=1;
+                               m_pActWay->AddNodeRef( m_rDocument.FindNode( nodeRefId ) );
+                                 Node * node = m_rDocument.FindNode( nodeRefId );
+                                 if(node != 0 ){
+                                   node->numsOfUse+=1;
+                                 }else {
+                                   std::cout << "Reference nd=" << nodeRefId << " has no corresponding Node Entry (Maybe Node entry after Reference?)" << std::endl;
+                                 }
                        }
                }
        }

Change History

Changed 18 months ago by anton

  • status changed from new to closed
  • resolution set to fixed

Thanks Paul! I applied your patch, so it's in trunk now.

Note: See TracTickets for help on using tickets.