[FFmpeg-devel] [PATCH 2/2] avutil/log: Use bprint for part
Michael Niedermayer
michaelni at gmx.at
Sat Aug 10 13:57:14 CEST 2013
This should fix the issue with strings longer than 1024
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
libavutil/log.c | 45 ++++++++++++++++++++++++++-------------------
1 file changed, 26 insertions(+), 19 deletions(-)
diff --git a/libavutil/log.c b/libavutil/log.c
index cde7c12..53be3ea 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -35,6 +35,7 @@
#include <stdarg.h>
#include <stdlib.h>
#include "avutil.h"
+#include "bprint.h"
#include "common.h"
#include "internal.h"
#include "log.h"
@@ -168,30 +169,33 @@ static int get_category(void *ptr){
}
static void format_line(void *ptr, int level, const char *fmt, va_list vl,
- char part[3][LINE_SZ], int part_size, int *print_prefix, int type[2])
+ AVBPrint part[3], int *print_prefix, int type[2])
{
AVClass* avc = ptr ? *(AVClass **) ptr : NULL;
- part[0][0] = part[1][0] = part[2][0] = 0;
+ av_bprint_init(part+0, 0, 1);
+ av_bprint_init(part+1, 0, 1);
+ av_bprint_init(part+2, 0, 65536);
+
if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16;
if (*print_prefix && avc) {
if (avc->parent_log_context_offset) {
AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) +
avc->parent_log_context_offset);
if (parent && *parent) {
- snprintf(part[0], part_size, "[%s @ %p] ",
+ av_bprintf(part+0, "[%s @ %p] ",
(*parent)->item_name(parent), parent);
if(type) type[0] = get_category(parent);
}
}
- snprintf(part[1], part_size, "[%s @ %p] ",
+ av_bprintf(part+1, "[%s @ %p] ",
avc->item_name(ptr), ptr);
if(type) type[1] = get_category(ptr);
}
- vsnprintf(part[2], part_size, fmt, vl);
+ av_vbprintf(part+2, fmt, vl);
- if(*part[0] || *part[1] || *part[2]) {
- char lastc = strlen(part[2]) ? part[2][strlen(part[2]) - 1] : 0;
+ if(*part[0].str || *part[1].str || *part[2].str) {
+ char lastc = part[2].len ? part[2].str[part[2].len - 1] : 0;
*print_prefix = lastc == '\n' || lastc == '\r';
}
}
@@ -199,9 +203,10 @@ static void format_line(void *ptr, int level, const char *fmt, va_list vl,
void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
char *line, int line_size, int *print_prefix)
{
- char part[3][LINE_SZ];
- format_line(ptr, level, fmt, vl, part, sizeof(part[0]), print_prefix, NULL);
- snprintf(line, line_size, "%s%s%s", part[0], part[1], part[2]);
+ AVBPrint part[3];
+ format_line(ptr, level, fmt, vl, part, print_prefix, NULL);
+ snprintf(line, line_size, "%s%s%s", part[0].str, part[1].str, part[2].str);
+ av_bprint_finalize(part+2, NULL);
}
void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
@@ -209,15 +214,15 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
static int print_prefix = 1;
static int count;
static char prev[LINE_SZ];
- char part[3][LINE_SZ];
+ AVBPrint part[3];
char line[LINE_SZ];
static int is_atty;
int type[2];
if (level > av_log_level)
return;
- format_line(ptr, level, fmt, vl, part, sizeof(part[0]), &print_prefix, type);
- snprintf(line, sizeof(line), "%s%s%s", part[0], part[1], part[2]);
+ format_line(ptr, level, fmt, vl, part, &print_prefix, type);
+ snprintf(line, sizeof(line), "%s%s%s", part[0].str, part[1].str, part[2].str);
#if HAVE_ISATTY
if (!is_atty)
@@ -229,6 +234,7 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
count++;
if (is_atty == 1)
fprintf(stderr, " Last message repeated %d times\r", count);
+ av_bprint_finalize(part+2, NULL);
return;
}
if (count > 0) {
@@ -236,12 +242,13 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
count = 0;
}
strcpy(prev, line);
- sanitize(part[0]);
- colored_fputs(type[0], part[0]);
- sanitize(part[1]);
- colored_fputs(type[1], part[1]);
- sanitize(part[2]);
- colored_fputs(av_clip(level >> 3, 0, 6), part[2]);
+ sanitize(part[0].str);
+ colored_fputs(type[0], part[0].str);
+ sanitize(part[1].str);
+ colored_fputs(type[1], part[1].str);
+ sanitize(part[2].str);
+ colored_fputs(av_clip(level >> 3, 0, 6), part[2].str);
+ av_bprint_finalize(part+2, NULL);
}
static void (*av_log_callback)(void*, int, const char*, va_list) =
--
1.7.9.5
More information about the ffmpeg-devel
mailing list