From 6668eeb68eaeeff2b0686d07d7ec6e1cdf88c882 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 9 Mar 2018 19:03:05 +0100 Subject: [PATCH] Fix possible nullptr dereferencing. --- code/D3MFExporter.cpp | 42 ++++++++++++++++++++++++++++++++++++-- include/assimp/fast_atof.h | 2 -- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/code/D3MFExporter.cpp b/code/D3MFExporter.cpp index a74280af7..98b15b10b 100644 --- a/code/D3MFExporter.cpp +++ b/code/D3MFExporter.cpp @@ -49,8 +49,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include - +#include #include + #include "3MFXmlTags.h" #include "D3MFOpcPackage.h" @@ -204,8 +205,45 @@ void D3MFExporter::writeHeader() { mModelOutput << std::endl; } -void D3MFExporter::writeBaseMaterials() { +static std::string to_hex( int to_convert ) { + std::string result; + std::stringstream ss; + ss << std::hex << to_convert; + ss >> result; + return result; +} +void D3MFExporter::writeBaseMaterials() { + mModelOutput << "\n"; + for ( size_t i = 0; i < mScene->mNumMaterials; ++i ) { + aiMaterial *mat = mScene->mMaterials[ i ]; + std::string strName; + aiString name; + if ( mat->Get( AI_MATKEY_NAME, name ) != aiReturn_SUCCESS ) { + strName = "basemat_" + to_string( i ); + } else { + strName = name.C_Str(); + } + std::string hexDiffuseColor; + aiColor4D color; + if ( mat->Get( AI_MATKEY_COLOR_DIFFUSE, color ) == aiReturn_SUCCESS ) { + hexDiffuseColor = "#"; + std::string tmp; + tmp = to_hex( color.r ); + hexDiffuseColor += tmp; + tmp = to_hex( color.g ); + hexDiffuseColor += tmp; + tmp = to_hex( color.b ); + hexDiffuseColor += tmp; + tmp = to_hex( color.a ); + hexDiffuseColor += tmp; + } else { + hexDiffuseColor = "#FFFFFFFF"; + } + + mModelOutput << "\n"; + } + mModelOutput << "\n"; } void D3MFExporter::writeObjects() { diff --git a/include/assimp/fast_atof.h b/include/assimp/fast_atof.h index fced5307a..e66f1b37d 100644 --- a/include/assimp/fast_atof.h +++ b/include/assimp/fast_atof.h @@ -146,7 +146,6 @@ uint8_t HexOctetToDecimal(const char* in) { return ((uint8_t)HexDigitToDecimal(in[0])<<4)+(uint8_t)HexDigitToDecimal(in[1]); } - // ------------------------------------------------------------------------------------ // signed variant of strtoul10 // ------------------------------------------------------------------------------------ @@ -353,7 +352,6 @@ ai_real fast_atof(const char* c) { return ret; } - inline ai_real fast_atof( const char* c, const char** cout) { ai_real ret(0.0);