diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-08-10 13:52:53 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-08-10 18:17:30 +0200 |
commit | 148310ca1659e3be95a2e87a8e30d1894a32d6d6 (patch) | |
tree | a876708fe53bd796e7294195a7568e6f06c5c169 /libavutil/log.c | |
parent | 112c970ca62de2f43019a4cc787d12a0b88d2fbc (diff) | |
download | ffmpeg-148310ca1659e3be95a2e87a8e30d1894a32d6d6.tar.gz |
avutil/log: Use bprint for part
This should fix the issue with strings longer than 1024
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil/log.c')
-rw-r--r-- | libavutil/log.c | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/libavutil/log.c b/libavutil/log.c index cde7c12e4d..53be3ea4e9 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) = |