fix review finding: dereference after null-check.

pull/2290/head
Kim Kulling 2018-12-31 14:47:54 +01:00
parent 425a784b23
commit c63b1a1fd5
2 changed files with 10 additions and 9 deletions

View File

@ -124,26 +124,28 @@ bool EmbedTexturesProcess::addTexture(aiScene* pScene, std::string path) const {
file.read(reinterpret_cast<char*>(imageContent), imageSize); file.read(reinterpret_cast<char*>(imageContent), imageSize);
// Enlarging the textures table // Enlarging the textures table
auto textureId = pScene->mNumTextures++; unsigned int textureId = pScene->mNumTextures++;
auto oldTextures = pScene->mTextures; auto oldTextures = pScene->mTextures;
pScene->mTextures = new aiTexture*[pScene->mNumTextures]; pScene->mTextures = new aiTexture*[pScene->mNumTextures];
memmove(pScene->mTextures, oldTextures, sizeof(aiTexture*) * (pScene->mNumTextures - 1u)); ::memmove(pScene->mTextures, oldTextures, sizeof(aiTexture*) * (pScene->mNumTextures - 1u));
// Add the new texture // Add the new texture
auto pTexture = new aiTexture(); auto pTexture = new aiTexture;
pTexture->mHeight = 0; // Means that this is still compressed pTexture->mHeight = 0; // Means that this is still compressed
pTexture->mWidth = static_cast<uint32_t>(imageSize); pTexture->mWidth = static_cast<uint32_t>(imageSize);
pTexture->pcData = imageContent; pTexture->pcData = imageContent;
auto extension = path.substr(path.find_last_of('.') + 1u); auto extension = path.substr(path.find_last_of('.') + 1u);
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
if (extension == "jpeg") extension = "jpg"; if (extension == "jpeg") {
extension = "jpg";
}
size_t len = extension.size(); size_t len = extension.size();
if (len > HINTMAXTEXTURELEN -1) { if (len > HINTMAXTEXTURELEN -1 ) {
len = HINTMAXTEXTURELEN - 1; len = HINTMAXTEXTURELEN - 1;
} }
strncpy(pTexture->achFormatHint, extension.c_str(), len); ::strncpy(pTexture->achFormatHint, extension.c_str(), len);
pScene->mTextures[textureId] = pTexture; pScene->mTextures[textureId] = pTexture;
return true; return true;

View File

@ -400,6 +400,7 @@ void Q3BSPFileImporter::createTriangleTopology( const Q3BSP::Q3BSPModel *pModel,
if (nullptr != m_pCurrentFace) { if (nullptr != m_pCurrentFace) {
m_pCurrentFace->mNumIndices = 3; m_pCurrentFace->mNumIndices = 3;
m_pCurrentFace->mIndices = new unsigned int[3]; m_pCurrentFace->mIndices = new unsigned int[3];
m_pCurrentFace->mIndices[ idx ] = vertIdx;
} }
} }
@ -409,9 +410,7 @@ void Q3BSPFileImporter::createTriangleTopology( const Q3BSP::Q3BSPModel *pModel,
pMesh->mTextureCoords[ 0 ][ vertIdx ].Set( pVertex->vTexCoord.x, pVertex->vTexCoord.y, 0.0f ); pMesh->mTextureCoords[ 0 ][ vertIdx ].Set( pVertex->vTexCoord.x, pVertex->vTexCoord.y, 0.0f );
pMesh->mTextureCoords[ 1 ][ vertIdx ].Set( pVertex->vLightmap.x, pVertex->vLightmap.y, 0.0f ); pMesh->mTextureCoords[ 1 ][ vertIdx ].Set( pVertex->vLightmap.x, pVertex->vLightmap.y, 0.0f );
m_pCurrentFace->mIndices[ idx ] = vertIdx;
vertIdx++; vertIdx++;
idx++; idx++;
} }
} }