mirror of
https://gitlab.com/Mr_Goldberg/goldberg_emulator.git
synced 2024-06-18 10:28:58 +00:00
Reworked _trace function
Compute the string length, alloc that much chars then process the vsnprintf
This commit is contained in:
parent
8751d4e279
commit
fb3090bc72
25
dll/base.cpp
25
dll/base.cpp
|
@ -27,23 +27,19 @@
|
||||||
// So process it before sending it to debug console
|
// So process it before sending it to debug console
|
||||||
bool _trace(const char* format, ...)
|
bool _trace(const char* format, ...)
|
||||||
{
|
{
|
||||||
constexpr const int len = 1024; // Initial buffer size, hope it is big enought, we will exapnd it if not.
|
|
||||||
int res;
|
|
||||||
char *buffer = new char[len];
|
|
||||||
|
|
||||||
va_list argptr;
|
va_list argptr;
|
||||||
va_start(argptr, format);
|
va_start(argptr, format);
|
||||||
res = vsnprintf(buffer, len, format, argptr);
|
va_list argptr2;
|
||||||
|
va_copy(argptr2, argptr);
|
||||||
|
int len;
|
||||||
|
|
||||||
|
len = vsnprintf(nullptr, 0, format, argptr);
|
||||||
|
|
||||||
|
char *buffer = new char[++len];
|
||||||
|
vsnprintf(buffer, len, format, argptr2);
|
||||||
|
|
||||||
va_end(argptr);
|
va_end(argptr);
|
||||||
if (res >= len)
|
va_end(argptr2);
|
||||||
{
|
|
||||||
delete[]buffer;
|
|
||||||
// Now we are sure we have enought free space to contain the string
|
|
||||||
buffer = new char[++res];
|
|
||||||
va_start(argptr, format);
|
|
||||||
vsnprintf(buffer, res, format, argptr);
|
|
||||||
va_end(argptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
OutputDebugString(buffer);
|
OutputDebugString(buffer);
|
||||||
delete[]buffer;
|
delete[]buffer;
|
||||||
|
@ -53,7 +49,6 @@ bool _trace(const char* format, ...)
|
||||||
#endif // VS_TRACE_DEBUG
|
#endif // VS_TRACE_DEBUG
|
||||||
#endif // EMU_RELEASE_BUILD
|
#endif // EMU_RELEASE_BUILD
|
||||||
|
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user