From c55be8ada303184192131b1157be95a3f9dc3553 Mon Sep 17 00:00:00 2001 From: aramis_acg Date: Thu, 28 Jan 2010 23:01:33 +0000 Subject: [PATCH] FIX: Cleaning up use of printf() format specifiers. %i mostly replaced by %u when appropriate. FIX: 'size_t to %i' printf() vulnerability. FIX: Subdivision, change line&point handling, add missing parentheses to clarify order. Add missing headers to vc9 workspace. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@533 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/ACLoader.cpp | 3 ++- code/Subdivision.cpp | 9 +++++---- code/TextureTransform.cpp | 15 ++++++++------- workspaces/vc9/assimp.vcproj | 8 ++++++++ 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/code/ACLoader.cpp b/code/ACLoader.cpp index 5522dbf86..d84bb0e9d 100644 --- a/code/ACLoader.cpp +++ b/code/ACLoader.cpp @@ -176,7 +176,8 @@ void AC3DImporter::LoadObjectSection(std::vector& objects) light->mAttenuationConstant = 1.f; // Generate a default name for both the light source and the node - light->mName.length = ::sprintf(light->mName.data,"ACLight_%i",mLights->size()-1); + // FIXME - what's the right way to print a size_t? Is 'zu' universally available? stick with the safe version. + light->mName.length = ::sprintf(light->mName.data,"ACLight_%i",static_cast(mLights->size())-1); obj.name = std::string( light->mName.data ); DefaultLogger::get()->debug("AC3D: Light source encountered"); diff --git a/code/Subdivision.cpp b/code/Subdivision.cpp index 21cc30aa0..252c842e9 100644 --- a/code/Subdivision.cpp +++ b/code/Subdivision.cpp @@ -177,7 +177,8 @@ void CatmullClarkSubdivider::Subdivide ( // point meshes are simply passed through. for (size_t s = 0; s < nmesh; ++s) { const aiMesh* i = smesh[s]; - if ((i->mPrimitiveTypes & aiPrimitiveType_LINE|aiPrimitiveType_POINT)==i->mPrimitiveTypes) { + // FIX - mPrimitiveTypes might not yet be initialized + if (i->mPrimitiveTypes && (i->mPrimitiveTypes & (aiPrimitiveType_LINE|aiPrimitiveType_POINT))==i->mPrimitiveTypes) { DefaultLogger::get()->debug("Catmull-Clark Subdivider: Skipping pure line/point mesh"); if (discard_input) { @@ -296,7 +297,7 @@ void CatmullClarkSubdivider::InternSubdivide ( // face points and original points. Every edge exists twice // if there is a neighboring face. // --------------------------------------------------------------------- - for (size_t t = 0, n = 0; t < nmesh; ++t) { + for (size_t t = 0; t < nmesh; ++t) { const aiMesh* mesh = smesh[t]; for (unsigned int i = 0; i < mesh->mNumFaces;++i) { @@ -342,8 +343,8 @@ void CatmullClarkSubdivider::InternSubdivide ( // faces in the mesh. They occur at outer model boundaries in non-closed // shapes. char tmp[512]; - sprintf(tmp,"Catmull-Clark Subdivider: got %i bad edges touching only one face (totally %i edges). ", - bad_cnt,edges.size()); + sprintf(tmp,"Catmull-Clark Subdivider: got %u bad edges touching only one face (totally %u edges). ", + bad_cnt,static_cast(edges.size())); DefaultLogger::get()->debug(tmp); }} diff --git a/code/TextureTransform.cpp b/code/TextureTransform.cpp index 4bb8f0263..d721ae799 100644 --- a/code/TextureTransform.cpp +++ b/code/TextureTransform.cpp @@ -359,7 +359,7 @@ void TextureTransformStep::Execute( aiScene* pScene) inChannels += mesh->GetNumUVChannels(); - if (!mesh->mTextureCoords[0] || trafo.empty() || trafo.size() == 1 && trafo.begin()->IsUntransformed()) { + if (!mesh->mTextureCoords[0] || trafo.empty() || (trafo.size() == 1 && trafo.begin()->IsUntransformed())) { outChannels += mesh->GetNumUVChannels(); continue; } @@ -371,10 +371,11 @@ void TextureTransformStep::Execute( aiScene* pScene) unsigned int untransformed = 0; MeshTrafoList::iterator it,it2; - for (it = trafo.begin(), it2;it != trafo.end(); ++it,++cnt) { + for (it = trafo.begin();it != trafo.end(); ++it,++cnt) { - if (!(*it).IsUntransformed()) + if (!(*it).IsUntransformed()) { need = true; + } if ((*it).lockedPos == AI_TT_UV_IDX_LOCK_TBD) { // Lock this index and make sure it won't be changed @@ -439,8 +440,8 @@ void TextureTransformStep::Execute( aiScene* pScene) if (size > AI_MAX_NUMBER_OF_TEXTURECOORDS) { if (!DefaultLogger::isNullLogger()) { - ::sprintf(buffer,"%i UV channels required but just %i available", - trafo.size(),AI_MAX_NUMBER_OF_TEXTURECOORDS); + ::sprintf(buffer,"%u UV channels required but just %u available", + static_cast(trafo.size()),AI_MAX_NUMBER_OF_TEXTURECOORDS); DefaultLogger::get()->error(buffer); } @@ -467,7 +468,7 @@ void TextureTransformStep::Execute( aiScene* pScene) // Write to the log if (!DefaultLogger::isNullLogger()) { - sprintf(buffer,"Mesh %i, channel %i: t(%.3f,%.3f), s(%.3f,%.3f), r(%.3f), %s%s", + sprintf(buffer,"Mesh %u, channel %u: t(%.3f,%.3f), s(%.3f,%.3f), r(%.3f), %s%s", q,n, (*it).mTranslation.x, (*it).mTranslation.y, @@ -550,7 +551,7 @@ void TextureTransformStep::Execute( aiScene* pScene) if (!DefaultLogger::isNullLogger()) { if (transformedChannels) { - ::sprintf(buffer,"TransformUVCoordsProcess end: %i output channels (in: %i, modified: %i)", + ::sprintf(buffer,"TransformUVCoordsProcess end: %u output channels (in: %u, modified: %u)", outChannels,inChannels,transformedChannels); DefaultLogger::get()->info(buffer); diff --git a/workspaces/vc9/assimp.vcproj b/workspaces/vc9/assimp.vcproj index a7875960d..ed77dc593 100644 --- a/workspaces/vc9/assimp.vcproj +++ b/workspaces/vc9/assimp.vcproj @@ -1235,6 +1235,14 @@ RelativePath="..\..\include\aiCamera.h" > + + + +