Dan Dimerman wrote:
Currently I have a piece of code that logs messages much in the same way as printf() :
void MyLogger::dump( const std::string& format, va_list& list ) { const unsigned short buf_size = 1024; char buffer[ buf_size ]; ::memset( buffer, 0, buf_size ); ::_vsnprintf( buffer, buf_size - 1, format.c_str(), list);
/.../ }
After many headaches (and crashes) due to mistaken format specification fields, I thought to upgrade my class's API to use boost::format, but alas, I couldn't find the way to feed the format object from a va_list. Is there a way?
Why do you think that boost::format together with va_list will be any safer than vsnprintf? If boost::format accepted va_list, it would have to guess types from format string, which will be as dangerous as it is for vsnprintf. - Volodya