Commit 886ff51e authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Instance: Properly compute log string

This is likely to break under MSVC
parent 15d97e9b
......@@ -197,10 +197,13 @@ public:
static_assert(signature_match<LogCb, void(int, const libvlc_log_t*, std::string)>::value,
"Mismatched log callback" );
auto wrapper = [logCb](int level, const libvlc_log_t* ctx, const char* format, va_list va) {
char message[256];
if ( vsnprintf( message, 256, format, va) != -1 )
VaCopy vaCopy( va );
int len = vsnprintf( nullptr, 0, format, vaCopy.va );
if ( len > 0 )
{
logCb( level, ctx, std::string{ message } );
std::unique_ptr<char[]> message{ new char[len] };
if ( vsnprintf( message.get(), len, format, va ) != -1 )
logCb( level, ctx, std::string{ message.get() } );
}
};
libvlc_log_set( *this, CallbackWrapper<(int)EventIdx::Log, libvlc_log_cb>::wrap( this, std::move( wrapper ) ),
......
......@@ -170,6 +170,25 @@ namespace VLC
return nullptr;
}
};
struct VaCopy
{
VaCopy(va_list va_)
{
va_copy( va, va_ );
}
~VaCopy()
{
va_end( va );
}
VaCopy( const VaCopy& ) = delete;
VaCopy& operator=(const VaCopy& ) = delete;
VaCopy( VaCopy&& ) = delete;
VaCopy& operator=( VaCopy&& ) = delete;
va_list va;
};
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment