X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=ffprobe.c;h=470001c4064abd37e2cd278cae1f0f90a36b5088;hb=5c9b9165cd82478a6d26294561767d60439040d3;hp=0f5a2f957af4ac5cb2322cb83d7debf072fd54b0;hpb=2f3b028c7117e03267ea7f88d0d612e70f1afc06;p=ffmpeg diff --git a/ffprobe.c b/ffprobe.c index 0f5a2f957af..470001c4064 100644 --- a/ffprobe.c +++ b/ffprobe.c @@ -335,6 +335,31 @@ fail: return NULL; } +#define ESCAPE_INIT_BUF_SIZE 256 + +#define ESCAPE_CHECK_SIZE(src, size, max_size) \ + if (size > max_size) { \ + char buf[64]; \ + snprintf(buf, sizeof(buf), "%s", src); \ + av_log(log_ctx, AV_LOG_WARNING, \ + "String '%s...' with is too big\n", buf); \ + return "FFPROBE_TOO_BIG_STRING"; \ + } + +#define ESCAPE_REALLOC_BUF(dst_size_p, dst_p, src, size) \ + if (*dst_size_p < size) { \ + char *q = av_realloc(*dst_p, size); \ + if (!q) { \ + char buf[64]; \ + snprintf(buf, sizeof(buf), "%s", src); \ + av_log(log_ctx, AV_LOG_WARNING, \ + "String '%s...' could not be escaped\n", buf); \ + return "FFPROBE_THIS_STRING_COULD_NOT_BE_ESCAPED"; \ + } \ + *dst_size_p = size; \ + *dst = q; \ + } + /* WRITERS */ /* Default output */ @@ -414,8 +439,6 @@ typedef struct { size_t buf_size; } JSONContext; -#define ESCAPE_INIT_BUF_SIZE 256 - static av_cold int json_init(WriterContext *wctx, const char *args, void *opaque) { JSONContext *json = wctx->priv; @@ -433,29 +456,6 @@ static av_cold void json_uninit(WriterContext *wctx) av_freep(&json->buf); } -#define ESCAPE_CHECK_SIZE(src, size, max_size) \ - if (size > max_size) { \ - char buf[64]; \ - snprintf(buf, sizeof(buf), "%s", src); \ - av_log(log_ctx, AV_LOG_WARNING, \ - "String '%s...' with is too big\n", buf); \ - return "FFPROBE_TOO_BIG_STRING"; \ - } - -#define ESCAPE_REALLOC_BUF(dst_size_p, dst_p, src, size) \ - if (*dst_size_p < size) { \ - char *q = av_realloc(*dst_p, size); \ - if (!q) { \ - char buf[64]; \ - snprintf(buf, sizeof(buf), "%s", src); \ - av_log(log_ctx, AV_LOG_WARNING, \ - "String '%s...' could not be escaped\n", buf); \ - return "FFPROBE_THIS_STRING_COULD_NOT_BE_ESCAPED"; \ - } \ - *dst_size_p = size; \ - *dst = q; \ - } - static const char *json_escape_str(char **dst, size_t *dst_size, const char *src, void *log_ctx) { @@ -809,26 +809,20 @@ static int probe_file(const char *filename) AVFormatContext *fmt_ctx; int ret; Writer *w; - const char *buf = print_format; - char *w_str = NULL, *w_args = NULL; + char *buf; + char *w_name = NULL, *w_args = NULL; WriterContext *wctx; writer_register_all(); - if (buf) { - w_str = av_get_token(&buf, "="); - if (*buf == '=') { - buf++; - w_args = av_get_token(&buf, ""); - } - } - - if (!w_str) - w_str = av_strdup("default"); + if (!print_format) + print_format = av_strdup("default"); + w_name = av_strtok(print_format, "=", &buf); + w_args = buf; - w = writer_get_by_name(w_str); + w = writer_get_by_name(w_name); if (!w) { - av_log(NULL, AV_LOG_ERROR, "Invalid output format '%s'\n", w_str); + av_log(NULL, AV_LOG_ERROR, "Unknown output format with name '%s'\n", w_name); ret = AVERROR(EINVAL); goto end; } @@ -848,8 +842,7 @@ static int probe_file(const char *filename) writer_close(&wctx); end: - av_free(w_str); - av_free(w_args); + av_freep(&print_format); return ret; }