Partially fixes #646. Values were incorrectly casted to int32_t and not uint32_t

This commit is contained in:
DennisOSRM 2013-07-09 14:25:32 +02:00
parent 9ab86ae2bf
commit f5124de327
3 changed files with 61 additions and 19 deletions

View File

@ -129,13 +129,13 @@ _RawRestrictionContainer XMLParser::_ReadXMLRestriction() {
xmlChar * type = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "type" );
if(xmlStrEqual(role, (const xmlChar *) "to") && xmlStrEqual(type, (const xmlChar *) "way")) {
restriction.toWay = atoi((const char*) ref);
restriction.toWay = stringToUint((const char*) ref);
}
if(xmlStrEqual(role, (const xmlChar *) "from") && xmlStrEqual(type, (const xmlChar *) "way")) {
restriction.fromWay = atoi((const char*) ref);
restriction.fromWay = stringToUint((const char*) ref);
}
if(xmlStrEqual(role, (const xmlChar *) "via") && xmlStrEqual(type, (const xmlChar *) "node")) {
restriction.restriction.viaNode = atoi((const char*) ref);
restriction.restriction.viaNode = stringToUint((const char*) ref);
}
if(NULL != type) {
@ -176,7 +176,7 @@ ExtractionWay XMLParser::_ReadXMLWay() {
if ( depth == childDepth && childType == 15 && xmlStrEqual( childName, ( const xmlChar* ) "way" ) == 1 ) {
xmlChar* id = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "id" );
way.id = atoi((char*)id);
way.id = stringToUint((char*)id);
xmlFree(id);
xmlFree( childName );
break;
@ -202,7 +202,7 @@ ExtractionWay XMLParser::_ReadXMLWay() {
} else if ( xmlStrEqual( childName, ( const xmlChar* ) "nd" ) == 1 ) {
xmlChar* ref = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "ref" );
if ( ref != NULL ) {
way.path.push_back( atoi(( const char* ) ref ) );
way.path.push_back( stringToUint(( const char* ) ref ) );
xmlFree( ref );
}
}
@ -227,7 +227,7 @@ ImportNode XMLParser::_ReadXMLNode() {
}
attribute = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "id" );
if ( attribute != NULL ) {
node.id = atoi(( const char* ) attribute );
node.id = stringToUint(( const char* ) attribute );
xmlFree( attribute );
}

View File

@ -1,17 +1,17 @@
/*
open source routing machine
Copyright (C) Dennis Luxen, others 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU AFFERO General Public License as published by
the Free Software Foundation; either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@ -21,17 +21,19 @@
#ifndef XMLPARSER_H_
#define XMLPARSER_H_
#include "BaseParser.h"
#include "../Util/StringUtil.h"
#include "../typedefs.h"
#include <libxml/xmlreader.h>
#include "../typedefs.h"
#include "BaseParser.h"
class XMLParser : public BaseParser {
public:
XMLParser(const char* filename, ExtractorCallbacks* ec, ScriptingEnvironment& se);
bool ReadHeader();
bool Parse();
private:
_RawRestrictionContainer _ReadXMLRestriction();
ExtractionWay _ReadXMLWay();

View File

@ -62,23 +62,63 @@ static inline char* printInt( char* buffer, int value ) {
}
static inline void intToString(const int value, std::string & output) {
// The largest 32-bit integer is 4294967295, that is 10 chars
// On the safe side, add 1 for sign, and 1 for trailing zero
output.clear();
std::back_insert_iterator<std::string> sink(output);
boost::spirit::karma::generate(sink, boost::spirit::karma::int_, value);
}
static inline void int64ToString(const int64_t value, std::string & output) {
output.clear();
std::back_insert_iterator<std::string> sink(output);
boost::spirit::karma::generate(sink, boost::spirit::karma::long_long, value);
}
static inline int stringToInt(const std::string& input) {
std::string::const_iterator realBeginOfNumber = input.begin();
std::string::const_iterator first_digit = input.begin();
//Delete any trailing white-spaces
while(realBeginOfNumber != input.end() && std::isspace(*realBeginOfNumber))
++realBeginOfNumber;
int value = 0; // 2
boost::spirit::qi::parse(realBeginOfNumber, input.end(), boost::spirit::int_, value); // 3
while(first_digit != input.end() && std::isspace(*first_digit)) {
++first_digit;
}
int value = 0;
boost::spirit::qi::parse(
first_digit,
input.end(),
boost::spirit::int_, value
);
return value;
}
static inline unsigned stringToUint(const std::string& input) {
std::string::const_iterator first_digit = input.begin();
//Delete any trailing white-spaces
while(first_digit != input.end() && std::isspace(*first_digit)) {
++first_digit;
}
int value = 0;
boost::spirit::qi::parse(
first_digit,
input.end(),
boost::spirit::uint_, value
);
return value;
}
static inline uint64_t stringToInt64(const std::string& input) {
std::string::const_iterator first_digit = input.begin();
//Delete any trailing white-spaces
while(first_digit != input.end() && std::isspace(*first_digit)) {
++first_digit;
}
uint64_t value = 0;
boost::spirit::qi::parse(
first_digit,
input.end(),
boost::spirit::long_long, value
);
return value;
}
static inline void doubleToString(const double value, std::string & output){
output.clear();
std::back_insert_iterator<std::string> sink(output);