diff --git a/code/3DSHelper.h b/code/3DSHelper.h index 444e7def3..2dbdff5f3 100644 --- a/code/3DSHelper.h +++ b/code/3DSHelper.h @@ -436,7 +436,7 @@ struct Mesh : public MeshWithSmoothingGroups // Generate a default name for the mesh char szTemp[128]; - ::ai_snprintf(szTemp, 128, "UNNAMED_%i",iCnt++); + ai_snprintf(szTemp, 128, "UNNAMED_%i",iCnt++); mName = szTemp; } diff --git a/code/PretransformVertices.cpp b/code/PretransformVertices.cpp index 9276a0ab6..d37bfd599 100644 --- a/code/PretransformVertices.cpp +++ b/code/PretransformVertices.cpp @@ -656,7 +656,7 @@ void PretransformVertices::Execute( aiScene* pScene) { aiNode* pcNode = *nodes = new aiNode(); pcNode->mParent = pScene->mRootNode; - pcNode->mName.length = ::sprintf(pcNode->mName.data,"light_%u",i); + pcNode->mName.length = ai_snprintf(pcNode->mName.data, MAXLEN, "light_%u",i); pScene->mLights[i]->mName = pcNode->mName; } // generate camera nodes diff --git a/code/SMDLoader.cpp b/code/SMDLoader.cpp index 6c681deac..2da7da019 100644 --- a/code/SMDLoader.cpp +++ b/code/SMDLoader.cpp @@ -216,7 +216,7 @@ void SMDImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS void SMDImporter::LogErrorNoThrow(const char* msg) { char szTemp[1024]; - sprintf(szTemp,"Line %u: %s",iLineNumber,msg); + ai_snprintf(szTemp,1024,"Line %u: %s",iLineNumber,msg); DefaultLogger::get()->error(szTemp); } @@ -226,7 +226,7 @@ void SMDImporter::LogWarning(const char* msg) { char szTemp[1024]; ai_assert(strlen(msg) < 1000); - sprintf(szTemp,"Line %u: %s",iLineNumber,msg); + ai_snprintf(szTemp,1024,"Line %u: %s",iLineNumber,msg); DefaultLogger::get()->warn(szTemp); } @@ -655,7 +655,7 @@ void SMDImporter::CreateOutputMaterials() pScene->mMaterials[iMat] = pcMat; aiString szName; - szName.length = (size_t)::sprintf(szName.data,"Texture_%u",iMat); + szName.length = (size_t)ai_snprintf(szName.data,MAXLEN,"Texture_%u",iMat); pcMat->AddProperty(&szName,AI_MATKEY_NAME); if (aszTextures[iMat].length()) diff --git a/code/StringUtils.h b/code/StringUtils.h index 5f7d6607f..32442ad78 100644 --- a/code/StringUtils.h +++ b/code/StringUtils.h @@ -44,7 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -namespace Assimp { +//namespace Assimp { /// @fn ai_snprintf /// @brief The portable version of the function snprintf ( C99 standard ), which works on visual studio compilers 2013 and earlier. @@ -53,7 +53,7 @@ namespace Assimp { /// @param format The format string /// @param ap The additional arguments. /// @return The number of written characters if the buffer size was big enough. If an encoding error occurs, a negative number is returned. -#if defined(_MSC_VER) && _MSC_VER < 1900 +//#if defined(_MSC_VER) && _MSC_VER < 1900 inline int c99_ai_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap) { int count(-1); @@ -67,32 +67,35 @@ namespace Assimp { return count; } - inline int ai_snprintf(char *s, size_t n, const char *fmt, ...) { +#if defined(_MSC_VER) && _MSC_VER < 1900 + + inline int ai_snprintf(char *outBuf, size_t size, const char *format, ...) { int count; va_list ap; - va_start(ap, fmt); - count = c99_ai_vsnprintf(outBuf, size, fmt, ap); + va_start(ap, format); + count = c99_ai_vsnprintf(outBuf, size, format, ap); va_end(ap); return count; } #else - - inline int ai_snprintf(char *s, size_t n, const char *format, ...) { +#define ai_snprintf snprintf + /*inline int ai_snprintf(char *outBuf, size_t size, const char *format, ...) { int count; - va_list ap; - va_start(ap, format); - count = snprintf(s, n, format, ap); - va_end(ap); + va_list args; + va_start(args, format); + count = c99_ai_vsnprintf(outBuf, size, format, args); +// count = ::snprintf(outBuf, size, format, args); + va_end(args); return count; - } + }*/ #endif -} // Namespace Assimp +//} // Namespace Assimp #endif // INCLUDED_AI_STRINGUTILS_H diff --git a/code/glTFAsset.inl b/code/glTFAsset.inl index 9b6a89077..bdc53b2d7 100644 --- a/code/glTFAsset.inl +++ b/code/glTFAsset.inl @@ -842,7 +842,7 @@ inline void AssetMetadata::Read(Document& doc) if (version != 1) { char msg[128]; - Assimp::ai_snprintf(msg, 128, "Unsupported glTF version: %d", version); + ai_snprintf(msg, 128, "Unsupported glTF version: %d", version); throw DeadlyImportError(msg); } } @@ -925,7 +925,7 @@ inline void Asset::Load(const std::string& pFile, bool isBinary) if (doc.HasParseError()) { char buffer[32]; - Assimp::ai_snprintf(buffer, 32, "%d", static_cast(doc.GetErrorOffset())); + ai_snprintf(buffer, 32, "%d", static_cast(doc.GetErrorOffset())); throw DeadlyImportError(std::string("JSON parse error, offset ") + buffer + ": " + GetParseError_En(doc.GetParseError())); } @@ -1029,9 +1029,9 @@ inline std::string Asset::FindUniqueID(const std::string& str, const char* suffi if (it == mUsedIds.end()) break; char buffer[256]; - int offset = Assimp::ai_snprintf(buffer, 256, "%s_", id.c_str()); + int offset = ai_snprintf(buffer, 256, "%s_", id.c_str()); for (int i = 0; it != mUsedIds.end(); ++i) { - Assimp::ai_snprintf(buffer + offset, 256, "%d", i); + ai_snprintf(buffer + offset, 256, "%d", i); id = buffer; it = mUsedIds.find(id); diff --git a/code/glTFAssetWriter.inl b/code/glTFAssetWriter.inl index c27581b5d..9f990ca36 100644 --- a/code/glTFAssetWriter.inl +++ b/code/glTFAssetWriter.inl @@ -190,7 +190,7 @@ namespace glTF { else { for (size_t i = 0; i < lst.size(); ++i) { char buffer[32]; - Assimp::ai_snprintf(buffer, 32, "%s_%d", semantic, int(i)); + ai_snprintf(buffer, 32, "%s_%d", semantic, int(i)); attrs.AddMember(Value(buffer, w.mAl).Move(), Value(lst[i]->id, w.mAl).Move(), w.mAl); } } diff --git a/tools/assimp_view/Background.cpp b/tools/assimp_view/Background.cpp index 27f2f1546..9737e585e 100644 --- a/tools/assimp_view/Background.cpp +++ b/tools/assimp_view/Background.cpp @@ -40,6 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "assimp_view.h" +#include "StringUtils.h" namespace AssimpView { @@ -385,7 +386,7 @@ void CBackgroundPainter::RecreateNativeResource() if (!szEnd)szEnd = szPath.c_str()-1; char szTemp[1024]; - sprintf(szTemp,"[ERROR] Unable to load background cubemap %s",szEnd+1); + ai_snprintf(szTemp,1024,"[ERROR] Unable to load background cubemap %s",szEnd+1); CLogDisplay::Instance().AddEntry(szTemp, D3DCOLOR_ARGB(0xFF,0xFF,0,0)); @@ -419,7 +420,7 @@ void CBackgroundPainter::RecreateNativeResource() if (!szEnd)szEnd = szPath.c_str()-1; char szTemp[1024]; - sprintf(szTemp,"[ERROR] Unable to load background texture %s",szEnd+1); + ai_snprintf(szTemp,1024,"[ERROR] Unable to load background texture %s",szEnd+1); CLogDisplay::Instance().AddEntry(szTemp, D3DCOLOR_ARGB(0xFF,0xFF,0,0)); diff --git a/tools/assimp_view/Display.cpp b/tools/assimp_view/Display.cpp index 69bcdb7c1..28c1550f3 100644 --- a/tools/assimp_view/Display.cpp +++ b/tools/assimp_view/Display.cpp @@ -41,6 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "assimp_view.h" #include "AnimEvaluator.h" #include "SceneAnimator.h" +#include "StringUtils.h" namespace AssimpView { @@ -168,13 +169,14 @@ int CDisplay::AddNodeToDisplayList( { iIndex += iDepth * 100; } - else iIndex += iDepth * 10; - sprintf(chTemp,"Node %u",iIndex); + else + iIndex += iDepth * 10; + ai_snprintf(chTemp, MAXLEN,"Node %u",iIndex); } else { - sprintf(chTemp,"%s",pcNode->mName.data); + ai_snprintf(chTemp, MAXLEN,"%s",pcNode->mName.data); } - sprintf(chTemp+strlen(chTemp), iIndex ? " (%i)" : " (%i meshes)",pcNode->mNumMeshes); + ai_snprintf(chTemp+strlen(chTemp), MAXLEN- strlen(chTemp), iIndex ? " (%i)" : " (%i meshes)",pcNode->mNumMeshes); TVITEMEXW tvi; TVINSERTSTRUCTW sNew; @@ -222,12 +224,12 @@ int CDisplay::AddMeshToDisplayList(unsigned int iIndex, HTREEITEM hRoot) char chTemp[MAXLEN]; if(0 == pcMesh->mName.length) { - sprintf(chTemp,"Mesh %u",iIndex); + ai_snprintf(chTemp,MAXLEN,"Mesh %u",iIndex); } else { - sprintf(chTemp,"%s",pcMesh->mName.data); + ai_snprintf(chTemp,MAXLEN,"%s",pcMesh->mName.data); } - sprintf(chTemp+strlen(chTemp), iIndex ? " (%i)" : " (%i faces)",pcMesh->mNumFaces); + ai_snprintf(chTemp+strlen(chTemp),MAXLEN-strlen(chTemp), iIndex ? " (%i)" : " (%i faces)",pcMesh->mNumFaces); TVITEMEXW tvi; TVINSERTSTRUCTW sNew; @@ -387,7 +389,7 @@ int CDisplay::AddTextureToDisplayList(unsigned int iType, if ('*' == *szPath->data) { int iIndex = atoi(szPath->data+1); - sprintf(chTempEmb,"Embedded #%i",iIndex); + ai_snprintf(chTempEmb,256,"Embedded #%i",iIndex); sz = chTempEmb; } else @@ -451,10 +453,10 @@ int CDisplay::AddTextureToDisplayList(unsigned int iType, break; }; if (bIsExtraOpacity) { - sprintf(chTemp,"%s %i ()",szType,iIndex+1); + ai_snprintf(chTemp,512,"%s %i ()",szType,iIndex+1); } else - sprintf(chTemp,"%s %i (%s)",szType,iIndex+1,sz); + ai_snprintf(chTemp,512,"%s %i (%s)",szType,iIndex+1,sz); TVITEMEX tvi; TVINSERTSTRUCT sNew; @@ -540,11 +542,11 @@ int CDisplay::AddMaterialToDisplayList(HTREEITEM hRoot, aiString szOut; if (AI_SUCCESS != aiGetMaterialString(pcMat,AI_MATKEY_NAME,&szOut)) { - sprintf(chTemp,"Material %i",iIndex+1); + ai_snprintf(chTemp,512,"Material %i",iIndex+1); } else { - sprintf(chTemp,"%s (%i)",szOut.data,iIndex+1); + ai_snprintf(chTemp,512,"%s (%i)",szOut.data,iIndex+1); } TVITEMEXW tvi; TVINSERTSTRUCTW sNew; @@ -821,24 +823,24 @@ int CDisplay::FillDefaultStatistics(void) } // and fill the statistic edit controls char szOut[1024]; - sprintf(szOut,"%i",(int)iNumVert); + ai_snprintf(szOut,1024,"%i",(int)iNumVert); SetDlgItemText(g_hDlg,IDC_EVERT,szOut); - sprintf(szOut,"%i",(int)iNumFaces); + ai_snprintf(szOut, 1024,"%i",(int)iNumFaces); SetDlgItemText(g_hDlg,IDC_EFACE,szOut); - sprintf(szOut,"%i",(int)g_pcAsset->pcScene->mNumMaterials); + ai_snprintf(szOut, 1024,"%i",(int)g_pcAsset->pcScene->mNumMaterials); SetDlgItemText(g_hDlg,IDC_EMAT,szOut); - sprintf(szOut,"%i",(int)g_pcAsset->pcScene->mNumMeshes); + ai_snprintf(szOut, 1024,"%i",(int)g_pcAsset->pcScene->mNumMeshes); SetDlgItemText(g_hDlg,IDC_EMESH,szOut); // need to get the number of nodes iNumVert = 0; GetNodeCount(g_pcAsset->pcScene->mRootNode,&iNumVert); - sprintf(szOut,"%i",(int)iNumVert); + ai_snprintf(szOut, 1024,"%i",(int)iNumVert); SetDlgItemText(g_hDlg,IDC_ENODEWND,szOut); // now get the number of unique shaders generated for the asset // (even if the environment changes this number won't change) - sprintf(szOut,"%i", CMaterialManager::Instance().GetShaderCount()); + ai_snprintf(szOut, 1024,"%i", CMaterialManager::Instance().GetShaderCount()); SetDlgItemText(g_hDlg,IDC_ESHADER,szOut); sprintf(szOut,"%.5f",(float)g_fLoadTime); diff --git a/tools/assimp_view/assimp_view.cpp b/tools/assimp_view/assimp_view.cpp index c3222299f..80cd3425f 100644 --- a/tools/assimp_view/assimp_view.cpp +++ b/tools/assimp_view/assimp_view.cpp @@ -41,6 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "assimp_view.h" +#include "StringUtils.h" #include using namespace std; @@ -257,8 +258,9 @@ int LoadAsset(void) g_pcAsset->mAnimator = new SceneAnimator( g_pcAsset->pcScene); // build a new caption string for the viewer - char szOut[MAX_PATH + 10]; - sprintf(szOut,AI_VIEW_CAPTION_BASE " [%s]",g_szFileName); + static const size_t Size = MAX_PATH + 10; + char szOut[Size]; + ai_snprintf(szOut, Size,AI_VIEW_CAPTION_BASE " [%s]",g_szFileName); SetWindowText(g_hDlg,szOut); // scale the asset vertices to fit into the viewer window