From: Kim Kulling Date: Sun, 4 Sep 2016 18:40:34 +0000 (+0200) Subject: Fix coverity findings: fix usage after free. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cc860ede66422c84d4a2211d52ad971011c1b0c5;p=platform%2Fupstream%2Fassimp.git Fix coverity findings: fix usage after free. --- diff --git a/code/SMDLoader.cpp b/code/SMDLoader.cpp index 7aef7bc..2db9f15 100644 --- a/code/SMDLoader.cpp +++ b/code/SMDLoader.cpp @@ -74,20 +74,22 @@ static const aiImporterDesc desc = { // ------------------------------------------------------------------------------------------------ // Constructor to be privately used by Importer SMDImporter::SMDImporter() - : configFrameID(), - mBuffer(), - pScene(), - iFileSize(), - iSmallestFrame(), - dLengthOfAnim(), - bHasUVs(), - iLineNumber() -{} +: configFrameID(), +mBuffer(), +pScene( nullptr ), +iFileSize( 0 ), +iSmallestFrame( -1 ), +dLengthOfAnim( 0.0 ), +bHasUVs(false ), +iLineNumber(-1) { + // empty +} // ------------------------------------------------------------------------------------------------ // Destructor, private as well -SMDImporter::~SMDImporter() -{} +SMDImporter::~SMDImporter() { + // empty +} // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. @@ -133,9 +135,8 @@ void SMDImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS // Allocate storage and copy the contents of the file to a memory buffer this->pScene = pScene; - std::vector buff(iFileSize+1); - TextFileToBuffer(file.get(),buff); - mBuffer = &buff[0]; + mBuffer.resize( iFileSize + 1 ); + TextFileToBuffer(file.get(), mBuffer ); iSmallestFrame = (1 << 31); bHasUVs = true; @@ -694,7 +695,7 @@ void SMDImporter::CreateOutputMaterials() // Parse the file void SMDImporter::ParseFile() { - const char* szCurrent = mBuffer; + const char* szCurrent = &mBuffer[0]; // read line per line ... for ( ;; ) diff --git a/code/SMDLoader.h b/code/SMDLoader.h index 0b069cc..96ea1d1 100644 --- a/code/SMDLoader.h +++ b/code/SMDLoader.h @@ -372,7 +372,7 @@ private: unsigned int configFrameID; /** Buffer to hold the loaded file */ - const char* mBuffer; + std::vector mBuffer; /** Output scene to be filled */