logger outbuf not initialized when ostream ctor is called

A crash happens on the static initialization of eoLogger eo::log;
at the end of the file eoLogger.cpp (line 255)

The reason is that the ctor used to initialize the std::eostream base class of
eoLogger is invoked with an _obuf argument while _obuf has not been initialized
already.

The solution is to call the function
std::ostream::init(&_obuf)
after the ctor initalizer list, i.e. inside the body ctor.
This commit is contained in:
marcello-ptr 2013-01-04 17:09:06 +01:00 committed by Johann Dreo
commit d706968c31

View file

@ -58,7 +58,7 @@ void eoLogger::_init()
}
eoLogger::eoLogger() :
std::ostream(&_obuf),
std::ostream(NULL),
_verbose("quiet", "verbose", "Set the verbose level", 'v'),
_printVerboseLevels(false, "print-verbose-levels", "Print verbose levels", 'l'),
@ -69,11 +69,12 @@ eoLogger::eoLogger() :
_fd(2),
_obuf(_fd, _contextLevel, _selectedLevel)
{
std::ostream::init(&_obuf);
_init();
}
eoLogger::eoLogger(eo::file file) :
std::ostream(&_obuf),
std::ostream(NULL),
_verbose("quiet", "verbose", "Set the verbose level", 'v'),
_printVerboseLevels(false, "print-verbose-levels", "Print verbose levels", 'l'),
@ -84,6 +85,7 @@ eoLogger::eoLogger(eo::file file) :
_fd(2),
_obuf(_fd, _contextLevel, _selectedLevel)
{
std::ostream::init(&_obuf);
_init();
*this << file;
}