From 4a5c483ac43980be0a3d3c4b28a9b3bae267e162 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 9 May 2017 21:03:20 +0200 Subject: [PATCH] AMFImporter: make test against nullptr dereferencing meaningful. --- code/AMFImporter_Postprocess.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/code/AMFImporter_Postprocess.cpp b/code/AMFImporter_Postprocess.cpp index 743df8fc5..3a48d3b42 100644 --- a/code/AMFImporter_Postprocess.cpp +++ b/code/AMFImporter_Postprocess.cpp @@ -261,21 +261,20 @@ size_t AMFImporter::PostprocessHelper_GetTextureID_Or_Create(const std::string& size_t off_b = 0; // Calculate size of the target array and rule how data will be copied. - if ( nullptr != src_texture ) { - if(!pID_R.empty()) { - tex_size += src_texture[0]->Data.size(); step++, off_g++, off_b++; - } - if(!pID_G.empty()) { - tex_size += src_texture[1]->Data.size(); step++, off_b++; - } - if(!pID_B.empty()) { - tex_size += src_texture[2]->Data.size(); step++; - } - if(!pID_A.empty()) { - tex_size += src_texture[3]->Data.size(); step++; - } + if(!pID_R.empty() && nullptr != src_texture[ 0 ] ) { + tex_size += src_texture[0]->Data.size(); step++, off_g++, off_b++; } - // Create target array. + if(!pID_G.empty() && nullptr != src_texture[ 1 ] ) { + tex_size += src_texture[1]->Data.size(); step++, off_b++; + } + if(!pID_B.empty() && nullptr != src_texture[ 2 ] ) { + tex_size += src_texture[2]->Data.size(); step++; + } + if(!pID_A.empty() && nullptr != src_texture[ 3 ] ) { + tex_size += src_texture[3]->Data.size(); step++; + } + + // Create target array. converted_texture.Data = new uint8_t[tex_size]; // And copy data auto CopyTextureData = [&](const std::string& pID, const size_t pOffset, const size_t pStep, const uint8_t pSrcTexNum) -> void