From 08cdf05b3e257fca36fef0920dec302a23bf0333 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 7 Mar 2003 08:52:51 +0000 Subject: [PATCH] Fix to comment record and longID length using both inbedded null's and rec length to determine the length of a string. --- src/osgPlugins/flt/flt2osg.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/osgPlugins/flt/flt2osg.cpp b/src/osgPlugins/flt/flt2osg.cpp index 2181dba0a..24170a2b7 100644 --- a/src/osgPlugins/flt/flt2osg.cpp +++ b/src/osgPlugins/flt/flt2osg.cpp @@ -68,6 +68,14 @@ using namespace flt; +unsigned int mystrnlen(char *s, unsigned int maxLen) +{ + for (unsigned int i = 0; i < maxLen; i++) + { + if (!s[i]) return i; + } + return maxLen; +} ConvertFromFLT::ConvertFromFLT() : _faceColor(1,1,1,1) @@ -326,9 +334,8 @@ void ConvertFromFLT::visitLongID(osg::Group& osgParent, LongIDRecord* rec) { SLongID *pSLongID = (SLongID*)rec->getData(); - unsigned int stingLength = strlen(pSLongID->szIdent); - if (stingLength>rec->getBodyLength()) stingLength=rec->getBodyLength(); - osgParent.setName(std::string(pSLongID->szIdent,stingLength)); + unsigned int stringLength = mystrnlen(pSLongID->szIdent,rec->getBodyLength()); + osgParent.setName(std::string(pSLongID->szIdent,stringLength)); } @@ -339,7 +346,8 @@ void ConvertFromFLT::visitComment(osg::Group& osgParent, CommentRecord* rec) //std::cout << "ConvertFromFLT::visitComment '"<szComment,pSComment->RecHeader.length()-4)<<"'"<szComment<<"'"<szComment); + unsigned int stringLength = mystrnlen(pSComment->szComment,rec->getBodyLength()); + std::string commentfield(pSComment->szComment,stringLength); unsigned int front_of_line = 0; unsigned int end_of_line = 0; while (end_of_line