I'm currently seeking for solutions or advices on how to fix my problem.
I have a logger that has a Write method having a variable argument list like so:
[code]void Logger::Write( S32 p_LogType, CZSTRING p_Msg, ... )[/code]
Currently the function is defined like this:
va_start( va_args, p_Msg );
char szBuffer[ LOGGER_STRINGBUFFERSIZE ];
vsprintf( szBuffer, p_Msg, va_args );
m_EngineLog << szBuffer << "
As you can see, I have defined a macro LOGGER_STRINGBUFFERSIZE to define the size of the char buffers to be created. Though, I have problems on when the arguments or the string itself is beyond the size. vsprintf causes a crash -- and I know why (buffer overflow). It's just I don't know my options.
On other code, I saw that a size parameter is required on the method but that's not an option for me, I really need it not to be explicitly stated. I tried to make a dynamic-sized array on-the-fly using new or malloc but I need to know the total size of the whole new string before even using vsprintf, which I don't know how. Any takes?
Any help is greatly appreciated.