Boost logo

Boost Users :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-12-22 05:44:58


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net