Skip to content
Snippets Groups Projects
Commit d76fe067 authored by Steve Lhomme's avatar Steve Lhomme
Browse files

Instance: avoid using asprintf

This is a GNU function. We have the tool in C++ to concatenate strings
and integers.

Fixes #14
parent c07bf8dd
No related branches found
No related tags found
1 merge request!36Instance: avoid using asprintf
Pipeline #326669 passed with stage
in 35 seconds
......@@ -33,6 +33,7 @@
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <cstring>
#include <cstdio>
......@@ -261,21 +262,17 @@ public:
char* psz_msg = message.get();
if (vsnprintf(psz_msg, len + 1, format, va) < 0 )
return;
char* psz_ctx;
if (asprintf(&psz_ctx, "[%s] (%s:%d) %s", psz_module, psz_file, i_line, psz_msg) < 0)
return;
std::unique_ptr<char, void(*)(void*)> ctxPtr(psz_ctx, &free);
#else
//MSVC treats passing nullptr as 1st vsnprintf(_s) as an error
char psz_msg[512];
if ( _vsnprintf_s( psz_msg, _TRUNCATE, format, va ) < 0 )
return;
char psz_ctx[1024];
if( sprintf_s( psz_ctx, "[%s] (%s:%d) %s", psz_module, psz_file,
i_line, psz_msg ) < 0 )
return;
#endif
logCb( level, ctx, std::string{ psz_ctx } );
std::ostringstream ss;
ss << '[' << psz_module << "] ("
<< psz_file << ':' << i_line
<< ") " << psz_msg;
logCb( level, ctx, ss.str() );
};
libvlc_log_set(*this, CallbackWrapper<(unsigned int)CallbackIdx::Log, libvlc_log_cb>::wrap( *m_callbacks, std::move(wrapper)),
m_callbacks.get() );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment