Skip to content

Commit

Permalink
samples/openstreetmap: Fix distorted map on Windows
Browse files Browse the repository at this point in the history
By using strtoll to parse node IDs instead of strtol,
because long is 32 bit on Windows, and IDs are larger than 2^31.
This caused confusion when lookig up referenced nodes.
Fixes omnetpp#1108.
  • Loading branch information
torokati44 committed Feb 23, 2024
1 parent ae7615b commit a836f3a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions samples/openstreetmap/OpenStreetMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ inline double strtod(const char *s)
return std::strtod(s, nullptr);
}

inline long strtol(const char *s)
inline long long strtoll(const char *s)
{
return std::strtol(s, nullptr, 10);
return std::strtoll(s, nullptr, 10);
}

OpenStreetMap::~OpenStreetMap()
Expand Down Expand Up @@ -62,7 +62,7 @@ Map OpenStreetMap::loadMap(cXMLElement *mapRoot)

for (cXMLElement *child : mapRoot->getChildrenByTagName("node")) {
Node *node = new Node();
node->id = strtol(child->getAttribute("id"));
node->id = strtoll(child->getAttribute("id"));
node->lat = strtod(child->getAttribute("lat"));
node->lon = strtod(child->getAttribute("lon"));

Expand All @@ -79,10 +79,10 @@ Map OpenStreetMap::loadMap(cXMLElement *mapRoot)

for (cXMLElement *child : mapRoot->getChildrenByTagName("way")) {
Way *way = new Way();
way->id = strtol(child->getAttribute("id"));
way->id = strtoll(child->getAttribute("id"));
for (cXMLElement *wayChild : child->getChildren()) {
if (strcmp(wayChild->getTagName(),"nd")==0) {
id_t ref = strtol(wayChild->getAttribute("ref"));
id_t ref = strtoll(wayChild->getAttribute("ref"));
ASSERT(nodeById.find(ref) != nodeById.end());
Node *node = nodeById[ref];
way->nodes.push_back(node);
Expand Down

0 comments on commit a836f3a

Please sign in to comment.