From 82289bf065e744f9a78b6e8ee23f39b1b48531ef Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Thu, 7 Jun 2012 11:56:20 +0000 Subject: [PATCH] Correctly interpret integer tokens without a leading #. Bug report: https://sourceforge.net/projects/ifcopenshell/forums/forum/1782717/topic/5280357 --- src/ifcparse/IfcParse.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index 550538b413..74c5b8a5ff 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -311,9 +311,13 @@ bool TokenFunc::isDatatype(Token t) { return ! isOperator(t) && startsWith(t, 'I'); } int TokenFunc::asInt(Token t) { - if ( ! isIdentifier(t) ) throw IfcException("Token is not an identifier"); const std::string str = asString(t); - return atoi(str.c_str()+1); + // In case of an ENTITY_INSTANCE_NAME skip the leading # + const char* start = str.c_str() + (isIdentifier(t) ? 1 : 0); + char* end; + long result = strtol(start,&end,10); + if ( start == end ) throw IfcException("Token is not an integer or identifier"); + return (int) result; } bool TokenFunc::asBool(Token t) { const std::string str = asString(t);