* [FFmpeg-devel] [PATCH v2 1/3] fftools/cmdutils: Add function to report error before exit
@ 2022-08-27 15:19 Andreas Rheinhardt
2022-08-27 15:19 ` [FFmpeg-devel] [PATCH v2 2/3] fftools: Use report_error_then_exit_program() for allocation failures Andreas Rheinhardt
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Andreas Rheinhardt @ 2022-08-27 15:19 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: James Almer, Andreas Rheinhardt
This is designed to improve and unify error handling for
allocation failures for the many (often small) allocations that we have
in the fftools. These typically either don't return an error message
or an error message that is not really helpful to the user
and can be replaced by a generic error message without loss of
information.
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
fftools/cmdutils.c | 6 ++++++
fftools/cmdutils.h | 11 +++++++++++
2 files changed, 17 insertions(+)
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 18e768b386..da3d391694 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -90,6 +90,12 @@ void register_exit(void (*cb)(int ret))
program_exit = cb;
}
+void report_and_exit(int ret)
+{
+ av_log(NULL, AV_LOG_FATAL, "%s\n", av_err2str(ret));
+ exit_program(AVUNERROR(ret));
+}
+
void exit_program(int ret)
{
if (program_exit)
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index d87e162ccd..4496221983 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -54,6 +54,17 @@ extern int hide_banner;
*/
void register_exit(void (*cb)(int ret));
+/**
+ * Reports an error corresponding to the provided
+ * AVERROR code and calls exit_program() with the
+ * corresponding POSIX error code.
+ * @note ret must be an AVERROR-value of a POSIX error code
+ * (i.e. AVERROR(EFOO) and not AVERROR_FOO).
+ * library functions can return both, so call this only
+ * with AVERROR(EFOO) of your own.
+ */
+void report_and_exit(int ret) av_noreturn;
+
/**
* Wraps exit with a program-specific cleanup routine.
*/
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* [FFmpeg-devel] [PATCH v2 2/3] fftools: Use report_error_then_exit_program() for allocation failures
2022-08-27 15:19 [FFmpeg-devel] [PATCH v2 1/3] fftools/cmdutils: Add function to report error before exit Andreas Rheinhardt
@ 2022-08-27 15:19 ` Andreas Rheinhardt
2022-08-27 15:19 ` [FFmpeg-devel] [PATCH v2 3/3] fftools/ffmpeg_opt: Check creation of new program Andreas Rheinhardt
2022-08-30 17:27 ` [FFmpeg-devel] [PATCH v2 1/3] fftools/cmdutils: Add function to report error before exit Andreas Rheinhardt
2 siblings, 0 replies; 4+ messages in thread
From: Andreas Rheinhardt @ 2022-08-27 15:19 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
fftools/cmdutils.c | 21 +++++--------
fftools/ffmpeg.c | 25 ++++++---------
fftools/ffmpeg_filter.c | 10 +++---
fftools/ffmpeg_opt.c | 70 ++++++++++++++++-------------------------
fftools/ffprobe.c | 6 ++--
fftools/opt_common.c | 6 ++--
6 files changed, 52 insertions(+), 86 deletions(-)
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index da3d391694..f911c52be2 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -656,7 +656,7 @@ static void init_parse_context(OptionParseContext *octx,
octx->nb_groups = nb_groups;
octx->groups = av_calloc(octx->nb_groups, sizeof(*octx->groups));
if (!octx->groups)
- exit_program(1);
+ report_and_exit(AVERROR(ENOMEM));
for (i = 0; i < octx->nb_groups; i++)
octx->groups[i].group_def = &groups[i];
@@ -964,11 +964,8 @@ AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
if (!s->nb_streams)
return NULL;
opts = av_calloc(s->nb_streams, sizeof(*opts));
- if (!opts) {
- av_log(NULL, AV_LOG_ERROR,
- "Could not alloc memory for stream options.\n");
- exit_program(1);
- }
+ if (!opts)
+ report_and_exit(AVERROR(ENOMEM));
for (i = 0; i < s->nb_streams; i++)
opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id,
s, s->streams[i], NULL);
@@ -983,10 +980,8 @@ void *grow_array(void *array, int elem_size, int *size, int new_size)
}
if (*size < new_size) {
uint8_t *tmp = av_realloc_array(array, new_size, elem_size);
- if (!tmp) {
- av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\n");
- exit_program(1);
- }
+ if (!tmp)
+ report_and_exit(AVERROR(ENOMEM));
memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
*size = new_size;
return tmp;
@@ -999,10 +994,8 @@ void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems)
void *new_elem;
if (!(new_elem = av_mallocz(elem_size)) ||
- av_dynarray_add_nofree(ptr, nb_elems, new_elem) < 0) {
- av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\n");
- exit_program(1);
- }
+ av_dynarray_add_nofree(ptr, nb_elems, new_elem) < 0)
+ report_and_exit(AVERROR(ENOMEM));
return new_elem;
}
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index ef7177fc33..8f53f5c7ef 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1094,10 +1094,8 @@ static void do_subtitle_out(OutputFile *of,
return;
ret = av_new_packet(pkt, subtitle_out_max_size);
- if (ret < 0) {
- av_log(NULL, AV_LOG_FATAL, "Failed to allocate subtitle encode buffer\n");
- exit_program(1);
- }
+ if (ret < 0)
+ report_and_exit(AVERROR(ENOMEM));
sub->pts = pts;
// start_display_time is required to be 0
@@ -2345,7 +2343,7 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output,
if (!ist->sub2video.sub_queue)
ist->sub2video.sub_queue = av_fifo_alloc2(8, sizeof(AVSubtitle), AV_FIFO_FLAG_AUTO_GROW);
if (!ist->sub2video.sub_queue)
- exit_program(1);
+ report_and_exit(AVERROR(ENOMEM));
ret = av_fifo_write(ist->sub2video.sub_queue, &subtitle, 1);
if (ret < 0)
@@ -2874,7 +2872,7 @@ static void set_encoder_id(OutputFile *of, OutputStream *ost)
encoder_string_len = sizeof(LIBAVCODEC_IDENT) + strlen(ost->enc->name) + 2;
encoder_string = av_mallocz(encoder_string_len);
if (!encoder_string)
- exit_program(1);
+ report_and_exit(AVERROR(ENOMEM));
if (!of->bitexact && !ost->bitexact)
av_strlcpy(encoder_string, LIBAVCODEC_IDENT " ", encoder_string_len);
@@ -2897,10 +2895,8 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost,
n++;
size = n;
pts = av_malloc_array(size, sizeof(*pts));
- if (!pts) {
- av_log(NULL, AV_LOG_FATAL, "Could not allocate forced key frames array.\n");
- exit_program(1);
- }
+ if (!pts)
+ report_and_exit(AVERROR(ENOMEM));
p = kf;
for (i = 0; i < n; i++) {
@@ -2919,11 +2915,8 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost,
if (nb_ch > INT_MAX - size ||
!(pts = av_realloc_f(pts, size += nb_ch - 1,
- sizeof(*pts)))) {
- av_log(NULL, AV_LOG_FATAL,
- "Could not allocate forced key frames array.\n");
- exit_program(1);
- }
+ sizeof(*pts))))
+ report_and_exit(AVERROR(ENOMEM));
t = p[8] ? parse_time_or_die("force_key_frames", p + 8, 1) : 0;
t = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base);
@@ -3861,7 +3854,7 @@ static int process_input(int file_index)
dst_data = av_packet_new_side_data(pkt, src_sd->type, src_sd->size);
if (!dst_data)
- exit_program(1);
+ report_and_exit(AVERROR(ENOMEM));
memcpy(dst_data, src_sd->data, src_sd->size);
}
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 16622e49c1..8b32a80ebf 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -118,7 +118,7 @@ static const char *choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint)
av_bprintf(bprint, "%s%c", name, p[1] == AV_PIX_FMT_NONE ? '\0' : '|');
}
if (!av_bprint_is_complete(bprint))
- exit_program(1);
+ report_and_exit(AVERROR(ENOMEM));
return bprint->str;
} else
return NULL;
@@ -182,7 +182,7 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
InputFilter *ifilter;
if (!fg)
- exit_program(1);
+ report_and_exit(AVERROR(ENOMEM));
fg->index = nb_filtergraphs;
ofilter = ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs);
@@ -199,7 +199,7 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
ifilter->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW);
if (!ifilter->frame_queue)
- exit_program(1);
+ report_and_exit(AVERROR(ENOMEM));
GROW_ARRAY(ist->filters, ist->nb_filters);
ist->filters[ist->nb_filters - 1] = ifilter;
@@ -223,7 +223,7 @@ static char *describe_filter_link(FilterGraph *fg, AVFilterInOut *inout, int in)
res = av_asprintf("%s:%s", ctx->filter->name,
avfilter_pad_get_name(pads, inout->pad_idx));
if (!res)
- exit_program(1);
+ report_and_exit(AVERROR(ENOMEM));
return res;
}
@@ -308,7 +308,7 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
ifilter->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW);
if (!ifilter->frame_queue)
- exit_program(1);
+ report_and_exit(AVERROR(ENOMEM));
GROW_ARRAY(ist->filters, ist->nb_filters);
ist->filters[ist->nb_filters - 1] = ifilter;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 8128dcf9fb..ccb79d920c 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -996,7 +996,7 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
if (hwaccel_device) {
ist->hwaccel_device = av_strdup(hwaccel_device);
if (!ist->hwaccel_device)
- exit_program(1);
+ report_and_exit(AVERROR(ENOMEM));
}
ist->hwaccel_pix_fmt = AV_PIX_FMT_NONE;
@@ -1027,10 +1027,8 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
ist->prev_pkt_pts = AV_NOPTS_VALUE;
ist->dec_ctx = avcodec_alloc_context3(ist->dec);
- if (!ist->dec_ctx) {
- av_log(NULL, AV_LOG_ERROR, "Error allocating the decoder context.\n");
- exit_program(1);
- }
+ if (!ist->dec_ctx)
+ report_and_exit(AVERROR(ENOMEM));
ret = avcodec_parameters_to_context(ist->dec_ctx, par);
if (ret < 0) {
@@ -1040,11 +1038,11 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
ist->decoded_frame = av_frame_alloc();
if (!ist->decoded_frame)
- exit_program(1);
+ report_and_exit(AVERROR(ENOMEM));
ist->pkt = av_packet_alloc();
if (!ist->pkt)
- exit_program(1);
+ report_and_exit(AVERROR(ENOMEM));
if (o->bitexact)
ist->dec_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
@@ -1094,7 +1092,7 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
ist->par = avcodec_parameters_alloc();
if (!ist->par)
- exit_program(1);
+ report_and_exit(AVERROR(ENOMEM));
ret = avcodec_parameters_from_context(ist->par, ist->dec_ctx);
if (ret < 0) {
@@ -1224,10 +1222,8 @@ static int open_input_file(OptionsContext *o, const char *filename)
/* get default parameters from command line */
ic = avformat_alloc_context();
- if (!ic) {
- print_error(filename, AVERROR(ENOMEM));
- exit_program(1);
- }
+ if (!ic)
+ report_and_exit(AVERROR(ENOMEM));
if (o->nb_audio_sample_rate) {
av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i, 0);
}
@@ -1476,10 +1472,8 @@ static char *get_line(AVIOContext *s, AVBPrint *bprint)
while ((c = avio_r8(s)) && c != '\n')
av_bprint_chars(bprint, c, 1);
- if (!av_bprint_is_complete(bprint)) {
- av_log(NULL, AV_LOG_FATAL, "Could not alloc buffer for reading preset.\n");
- exit_program(1);
- }
+ if (!av_bprint_is_complete(bprint))
+ report_and_exit(AVERROR(ENOMEM));
return bprint->str;
}
@@ -1567,10 +1561,8 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
double qscale = -1;
int i;
- if (!st) {
- av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n");
- exit_program(1);
- }
+ if (!st)
+ report_and_exit(AVERROR(ENOMEM));
if (oc->nb_streams - 1 < o->nb_streamid_map)
st->id = o->streamid_map[oc->nb_streams - 1];
@@ -1592,19 +1584,17 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
if (ost->enc) {
ost->enc_ctx = avcodec_alloc_context3(ost->enc);
- if (!ost->enc_ctx) {
- av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding context.\n");
- exit_program(1);
- }
+ if (!ost->enc_ctx)
+ report_and_exit(AVERROR(ENOMEM));
}
ost->filtered_frame = av_frame_alloc();
if (!ost->filtered_frame)
- exit_program(1);
+ report_and_exit(AVERROR(ENOMEM));
ost->pkt = av_packet_alloc();
if (!ost->pkt)
- exit_program(1);
+ report_and_exit(AVERROR(ENOMEM));
if (ost->enc) {
AVIOContext *s = NULL;
@@ -1897,28 +1887,22 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in
MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st);
if (intra_matrix) {
- if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64))) {
- av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
- exit_program(1);
- }
+ if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64)))
+ report_and_exit(AVERROR(ENOMEM));
parse_matrix_coeffs(video_enc->intra_matrix, intra_matrix);
}
MATCH_PER_STREAM_OPT(chroma_intra_matrices, str, chroma_intra_matrix, oc, st);
if (chroma_intra_matrix) {
uint16_t *p = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64);
- if (!p) {
- av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
- exit_program(1);
- }
+ if (!p)
+ report_and_exit(AVERROR(ENOMEM));
video_enc->chroma_intra_matrix = p;
parse_matrix_coeffs(p, chroma_intra_matrix);
}
MATCH_PER_STREAM_OPT(inter_matrices, str, inter_matrix, oc, st);
if (inter_matrix) {
- if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64))) {
- av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for inter matrix.\n");
- exit_program(1);
- }
+ if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64)))
+ report_and_exit(AVERROR(ENOMEM));
parse_matrix_coeffs(video_enc->inter_matrix, inter_matrix);
}
@@ -1975,7 +1959,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in
MATCH_PER_STREAM_OPT(passlogfiles, str, ost->logfile_prefix, oc, st);
if (ost->logfile_prefix &&
!(ost->logfile_prefix = av_strdup(ost->logfile_prefix)))
- exit_program(1);
+ report_and_exit(AVERROR(ENOMEM));
if (do_pass) {
char logfilename[1024];
@@ -2055,7 +2039,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in
ost->last_frame = av_frame_alloc();
if (!ost->last_frame)
- exit_program(1);
+ report_and_exit(AVERROR(ENOMEM));
} else
check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_VIDEO);
@@ -2146,7 +2130,7 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in
ost->audio_channels_mapped + 1,
sizeof(*ost->audio_channels_map)
) < 0 )
- exit_program(1);
+ report_and_exit(AVERROR(ENOMEM));
ost->audio_channels_map[ost->audio_channels_mapped++] = map->channel_idx;
}
@@ -2875,7 +2859,7 @@ static void set_channel_layout(OutputFilter *f, OutputStream *ost)
/* Pass the layout through for all orders but UNSPEC */
err = av_channel_layout_copy(&f->ch_layout, &ost->enc_ctx->ch_layout);
if (err < 0)
- exit_program(1);
+ report_and_exit(AVERROR(ENOMEM));
return;
}
@@ -2896,7 +2880,7 @@ static void set_channel_layout(OutputFilter *f, OutputStream *ost)
/* Use it if one is found */
err = av_channel_layout_copy(&f->ch_layout, &ost->enc->ch_layouts[i]);
if (err < 0)
- exit_program(1);
+ report_and_exit(AVERROR(ENOMEM));
return;
}
/* If no layout for the amount of channels requested was found, use the default
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 8983dc28cc..3344a06409 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -3291,10 +3291,8 @@ static int open_input_file(InputFile *ifile, const char *filename,
int scan_all_pmts_set = 0;
fmt_ctx = avformat_alloc_context();
- if (!fmt_ctx) {
- print_error(filename, AVERROR(ENOMEM));
- exit_program(1);
- }
+ if (!fmt_ctx)
+ report_and_exit(AVERROR(ENOMEM));
if (!av_dict_get(format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
av_dict_set(&format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
diff --git a/fftools/opt_common.c b/fftools/opt_common.c
index ae5e28a5af..7cd8b1c66e 100644
--- a/fftools/opt_common.c
+++ b/fftools/opt_common.c
@@ -639,10 +639,8 @@ static unsigned get_codecs_sorted(const AVCodecDescriptor ***rcodecs)
while ((desc = avcodec_descriptor_next(desc)))
nb_codecs++;
- if (!(codecs = av_calloc(nb_codecs, sizeof(*codecs)))) {
- av_log(NULL, AV_LOG_ERROR, "Out of memory\n");
- exit_program(1);
- }
+ if (!(codecs = av_calloc(nb_codecs, sizeof(*codecs))))
+ report_and_exit(AVERROR(ENOMEM));
desc = NULL;
while ((desc = avcodec_descriptor_next(desc)))
codecs[i++] = desc;
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* [FFmpeg-devel] [PATCH v2 3/3] fftools/ffmpeg_opt: Check creation of new program
2022-08-27 15:19 [FFmpeg-devel] [PATCH v2 1/3] fftools/cmdutils: Add function to report error before exit Andreas Rheinhardt
2022-08-27 15:19 ` [FFmpeg-devel] [PATCH v2 2/3] fftools: Use report_error_then_exit_program() for allocation failures Andreas Rheinhardt
@ 2022-08-27 15:19 ` Andreas Rheinhardt
2022-08-30 17:27 ` [FFmpeg-devel] [PATCH v2 1/3] fftools/cmdutils: Add function to report error before exit Andreas Rheinhardt
2 siblings, 0 replies; 4+ messages in thread
From: Andreas Rheinhardt @ 2022-08-27 15:19 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Fixes Coverity issue #1512413.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
fftools/ffmpeg_opt.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index ccb79d920c..eddd421b70 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -2753,6 +2753,8 @@ static void of_add_programs(AVFormatContext *oc, const OptionsContext *o)
}
program = av_new_program(oc, progid);
+ if (!program)
+ report_and_exit(AVERROR(ENOMEM));
p = o->program[i].u.str;
while(*p) {
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 1/3] fftools/cmdutils: Add function to report error before exit
2022-08-27 15:19 [FFmpeg-devel] [PATCH v2 1/3] fftools/cmdutils: Add function to report error before exit Andreas Rheinhardt
2022-08-27 15:19 ` [FFmpeg-devel] [PATCH v2 2/3] fftools: Use report_error_then_exit_program() for allocation failures Andreas Rheinhardt
2022-08-27 15:19 ` [FFmpeg-devel] [PATCH v2 3/3] fftools/ffmpeg_opt: Check creation of new program Andreas Rheinhardt
@ 2022-08-30 17:27 ` Andreas Rheinhardt
2 siblings, 0 replies; 4+ messages in thread
From: Andreas Rheinhardt @ 2022-08-30 17:27 UTC (permalink / raw)
To: ffmpeg-devel
Andreas Rheinhardt:
> This is designed to improve and unify error handling for
> allocation failures for the many (often small) allocations that we have
> in the fftools. These typically either don't return an error message
> or an error message that is not really helpful to the user
> and can be replaced by a generic error message without loss of
> information.
>
> Reviewed-by: James Almer <jamrial@gmail.com>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> fftools/cmdutils.c | 6 ++++++
> fftools/cmdutils.h | 11 +++++++++++
> 2 files changed, 17 insertions(+)
>
> diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
> index 18e768b386..da3d391694 100644
> --- a/fftools/cmdutils.c
> +++ b/fftools/cmdutils.c
> @@ -90,6 +90,12 @@ void register_exit(void (*cb)(int ret))
> program_exit = cb;
> }
>
> +void report_and_exit(int ret)
> +{
> + av_log(NULL, AV_LOG_FATAL, "%s\n", av_err2str(ret));
> + exit_program(AVUNERROR(ret));
> +}
> +
> void exit_program(int ret)
> {
> if (program_exit)
> diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
> index d87e162ccd..4496221983 100644
> --- a/fftools/cmdutils.h
> +++ b/fftools/cmdutils.h
> @@ -54,6 +54,17 @@ extern int hide_banner;
> */
> void register_exit(void (*cb)(int ret));
>
> +/**
> + * Reports an error corresponding to the provided
> + * AVERROR code and calls exit_program() with the
> + * corresponding POSIX error code.
> + * @note ret must be an AVERROR-value of a POSIX error code
> + * (i.e. AVERROR(EFOO) and not AVERROR_FOO).
> + * library functions can return both, so call this only
> + * with AVERROR(EFOO) of your own.
> + */
> +void report_and_exit(int ret) av_noreturn;
> +
> /**
> * Wraps exit with a program-specific cleanup routine.
> */
Will apply tonight unless there are objections.
- Andreas
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-08-30 17:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-27 15:19 [FFmpeg-devel] [PATCH v2 1/3] fftools/cmdutils: Add function to report error before exit Andreas Rheinhardt
2022-08-27 15:19 ` [FFmpeg-devel] [PATCH v2 2/3] fftools: Use report_error_then_exit_program() for allocation failures Andreas Rheinhardt
2022-08-27 15:19 ` [FFmpeg-devel] [PATCH v2 3/3] fftools/ffmpeg_opt: Check creation of new program Andreas Rheinhardt
2022-08-30 17:27 ` [FFmpeg-devel] [PATCH v2 1/3] fftools/cmdutils: Add function to report error before exit Andreas Rheinhardt
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git