Commit 0247bdee authored by Reinhard Tartler's avatar Reinhard Tartler Committed by Reinhard Tartler

Fix races in default av_log handler

Prevent competing threads from overwriting (shared) buffers.

Original patch by: Michael Niedermayer <michaelni@gmx.at>
parent cf3ac543
...@@ -83,7 +83,8 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) ...@@ -83,7 +83,8 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
{ {
static int print_prefix=1; static int print_prefix=1;
static int count; static int count;
static char line[1024], prev[1024]; static char prev[1024];
char line[1024];
static int is_atty; static int is_atty;
AVClass* avc= ptr ? *(AVClass**)ptr : NULL; AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
if(level>av_log_level) if(level>av_log_level)
...@@ -108,7 +109,7 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) ...@@ -108,7 +109,7 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
if(!is_atty) is_atty= isatty(2) ? 1 : -1; if(!is_atty) is_atty= isatty(2) ? 1 : -1;
#endif #endif
if(print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev)){ if(print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strncmp(line, prev, sizeof line)){
count++; count++;
if(is_atty==1) if(is_atty==1)
fprintf(stderr, " Last message repeated %d times\r", count); fprintf(stderr, " Last message repeated %d times\r", count);
...@@ -119,7 +120,7 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) ...@@ -119,7 +120,7 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
count=0; count=0;
} }
colored_fputs(av_clip(level>>3, 0, 6), line); colored_fputs(av_clip(level>>3, 0, 6), line);
strcpy(prev, line); strncpy(prev, line, sizeof line);
} }
static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback; static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
......
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