[MOAB-dev] r3854 - MOAB/trunk/src
kraftche at cae.wisc.edu
kraftche at cae.wisc.edu
Wed May 5 18:07:17 CDT 2010
Author: kraftche
Date: 2010-05-05 18:07:17 -0500 (Wed, 05 May 2010)
New Revision: 3854
Modified:
MOAB/trunk/src/DebugOutput.cpp
MOAB/trunk/src/DebugOutput.hpp
Log:
fix bugs in DebugOutput
Modified: MOAB/trunk/src/DebugOutput.cpp
===================================================================
--- MOAB/trunk/src/DebugOutput.cpp 2010-05-05 23:06:46 UTC (rev 3853)
+++ MOAB/trunk/src/DebugOutput.cpp 2010-05-05 23:07:17 UTC (rev 3854)
@@ -117,17 +117,19 @@
process_line_buffer();
}
-void DebugOutput::print_real( const char* fmt, va_list args )
+void DebugOutput::print_real( const char* fmt, va_list args1, va_list args2 )
{
size_t idx = lineBuffer.size();
#ifdef HAVE_VSNPRINTF
// try once with remaining space in buffer
lineBuffer.resize( lineBuffer.capacity() );
- unsigned size = vsnprintf( &lineBuffer[idx], lineBuffer.size() - idx, fmt, args );
+ unsigned size = vsnprintf( &lineBuffer[idx], lineBuffer.size() - idx, fmt, args1 );
+ ++size; // trailing null
// if necessary, increase buffer size and retry
if (size > (lineBuffer.size() - idx)) {
lineBuffer.resize( idx + size );
- size = vsnprintf( &lineBuffer[idx], lineBuffer.size() - idx, fmt, args );
+ size = vsnprintf( &lineBuffer[idx], lineBuffer.size() - idx, fmt, args2 );
+ ++size; // trailing null
}
#else
// Guess how much space might be required.
@@ -135,18 +137,20 @@
// Guess a random large value of 81 characters per formatted argument.
unsigned exp_size = 27*strlen(fmt);
lineBuffer.resize( idx + exp_size );
- unsigned size = vsprintf( &lineBuffer[idx], fmt, args );
+ unsigned size = vsprintf( &lineBuffer[idx], fmt, args1 );
+ ++size; // trailing null
// check if we overflowed the buffer
if (size > exp_size) {
// crap!
- fprintf(stderr,"ERROR: Buffer overflow at %s:%d\n", __FILE__, __LINE__);
- lineBuffer.resize( idx + exp_size );
- size = vsprintf( &lineBuffer[idx], fmt, args );
+ fprintf(stderr,"ERROR: Buffer overflow at %s:%d\n", __FILE__, __LINE__);
+ lineBuffer.resize( idx + exp_size );
+ size = vsprintf( &lineBuffer[idx], fmt, args2 );
+ ++size; // trailing null
}
#endif
// less one because we don't want the trailing '\0'
- lineBuffer.resize(size-1);
+ lineBuffer.resize(idx+size-1);
process_line_buffer();
More information about the moab-dev
mailing list