From a836f3a0c725d53056a9f247e3c13a01e789a805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=96R=C3=96K=20Attila?= Date: Fri, 23 Feb 2024 11:45:59 +0100 Subject: [PATCH] samples/openstreetmap: Fix distorted map on Windows 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 https://github.com/omnetpp/omnetpp/issues/1108. --- samples/openstreetmap/OpenStreetMap.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/openstreetmap/OpenStreetMap.cc b/samples/openstreetmap/OpenStreetMap.cc index 51a2936672..97ac27121d 100644 --- a/samples/openstreetmap/OpenStreetMap.cc +++ b/samples/openstreetmap/OpenStreetMap.cc @@ -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() @@ -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")); @@ -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);