Skip to content

Commit

Permalink
[core] Use ThreadName::BUFSIZE in CreateLogLinePrefix()
Browse files Browse the repository at this point in the history
  • Loading branch information
quink-black authored and maxsharabayko committed Aug 4, 2021
1 parent d6f93a1 commit adba7af
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions srtcore/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,16 +595,20 @@ void LogDispatcher::CreateLogLinePrefix(std::ostringstream& serr)
{
using namespace std;

char tmp_buf[512];
SRT_STATIC_ASSERT(ThreadName::BUFSIZE >= sizeof("hh:mm:ss.") * 2, // multiply 2 for some margin
"ThreadName::BUFSIZE is too small to be used for strftime");
char tmp_buf[ThreadName::BUFSIZE];
if ( !isset(SRT_LOGF_DISABLE_TIME) )
{
// Not necessary if sending through the queue.
timeval tv;
gettimeofday(&tv, 0);
gettimeofday(&tv, NULL);
struct tm tm = SysLocalTime((time_t) tv.tv_sec);

strftime(tmp_buf, 512, "%X.", &tm);
serr << tmp_buf << setw(6) << setfill('0') << tv.tv_usec;
if (strftime(tmp_buf, sizeof(tmp_buf), "%X.", &tm))
{
serr << tmp_buf << setw(6) << setfill('0') << tv.tv_usec;
}
}

string out_prefix;
Expand Down

0 comments on commit adba7af

Please sign in to comment.