From d3506c24e73b28afd4ef91583bff16a6abc0e138 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 2 Jun 2023 18:57:53 +0200 Subject: [PATCH] Update ObjFileParser.cpp --- code/AssetLib/Obj/ObjFileParser.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/code/AssetLib/Obj/ObjFileParser.cpp b/code/AssetLib/Obj/ObjFileParser.cpp index 432023264..ad97a470b 100644 --- a/code/AssetLib/Obj/ObjFileParser.cpp +++ b/code/AssetLib/Obj/ObjFileParser.cpp @@ -458,11 +458,14 @@ void ObjFileParser::getFace(aiPrimitiveType type) { //OBJ USES 1 Base ARRAYS!!!! int iVal; auto end = m_DataIt; + // find either the buffer end or the '\0' while (end < m_DataItEnd && *end != '\0') ++end; + // avoid temporary string allocation if there is a zero if (end != m_DataItEnd) { iVal = ::atoi(&(*m_DataIt)); } else { + // otherwise make a zero terminated copy, which is safe to pass to atoi std::string number(&(*m_DataIt), m_DataItEnd - m_DataIt); iVal = ::atoi(number.c_str()); }