Assxml io function: use vsprintf for var-argument list.

pull/859/head
Kim Kulling 2016-04-17 21:33:11 +02:00
parent dec93efc92
commit a6e7938696
1 changed files with 22 additions and 14 deletions

View File

@ -65,13 +65,20 @@ namespace Assimp {
namespace AssxmlExport { namespace AssxmlExport {
int ioprintf( IOStream * io, const char * format, ... ) // -----------------------------------------------------------------------------------
{ int ioprintf( IOStream * io, const char *format, ... ) {
char sz[4096]; if ( nullptr == io ) {
return -1;
}
static const size_t Size = 4096;
char sz[ Size ];
size_t len( strlen( format ) );
::memset( sz, '\0', Size );
va_list va; va_list va;
va_start( va, format ); va_start( va, format );
int nSize = ai_snprintf( sz, 4096, format, va ); int nSize = std::vsnprintf( sz, Size-1, format, va );
ai_assert( nSize < 4096 ); ai_assert( nSize < Size );
va_end( va ); va_end( va );
io->Write( sz, sizeof(char), nSize ); io->Write( sz, sizeof(char), nSize );
@ -175,10 +182,10 @@ static std::string encodeXML(const std::string& data) {
// ----------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------
// Write a text model dump // Write a text model dump
void WriteDump(const aiScene* scene, IOStream* io, bool shortened) void WriteDump(const aiScene* scene, IOStream* io, bool shortened) {
{ time_t tt = ::time( NULL );
time_t tt = ::time(NULL); tm* p = ::gmtime( &tt );
tm* p = ::gmtime(&tt); ai_assert( nullptr != p );
// write header // write header
std::string header( std::string header(
@ -189,13 +196,14 @@ void WriteDump(const aiScene* scene, IOStream* io, bool shortened)
" %s\n" " %s\n"
"-->" "-->"
" \n\n" " \n\n"
"<Scene flags=\"%i\" postprocessing=\"%i\">\n" "<Scene flags=\"%d\" postprocessing=\"%i\">\n"
); );
ioprintf( io, header.c_str(), const unsigned int major( aiGetVersionMajor() );
aiGetVersionMajor(), aiGetVersionMinor(), aiGetVersionRevision(), asctime( p ), const unsigned int minor( aiGetVersionMinor() );
scene->mFlags, const unsigned int rev( aiGetVersionRevision() );
0 /*globalImporter->GetEffectivePostProcessing()*/ ); const char *curtime( asctime( p ) );
ioprintf( io, header.c_str(), major, minor, rev, curtime, scene->mFlags, 0 );
// write the node graph // write the node graph
WriteNode(scene->mRootNode, io, 0); WriteNode(scene->mRootNode, io, 0);