snprintf replacement: fix usage of ai_snprintf when snprintf is available.

pull/749/head
Kim Kulling 2016-01-06 19:25:35 +01:00
parent 6bfdeb6a12
commit d43a083dc1
9 changed files with 53 additions and 45 deletions

View File

@ -436,7 +436,7 @@ struct Mesh : public MeshWithSmoothingGroups<D3DS::Face>
// 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;
}

View File

@ -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

View File

@ -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())

View File

@ -44,7 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string.h>
#include <stdio.h>
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

View File

@ -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<int>(doc.GetErrorOffset()));
ai_snprintf(buffer, 32, "%d", static_cast<int>(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);

View File

@ -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);
}
}

View File

@ -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));

View File

@ -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 (<copy of diffuse #1>)",szType,iIndex+1);
ai_snprintf(chTemp,512,"%s %i (<copy of diffuse #1>)",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);

View File

@ -41,6 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "assimp_view.h"
#include "StringUtils.h"
#include <map>
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