diff mbox series

[FFmpeg-devel,21/60] fftools/ffmpeg_mux_init: fix variable shadowing

Message ID D41CE2FHWNE8.3CDK2ALGEIIUA@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,01/60] fftools/ffmpeg_opt: fix variable shadowing | expand

Commit Message

Marvin Scholz Sept. 8, 2024, 8:21 p.m. UTC
---
 fftools/ffmpeg_mux_init.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

Comments

Anton Khirnov Sept. 13, 2024, 10 a.m. UTC | #1
Quoting Marvin Scholz (2024-09-08 22:21:03)
> ---
>  fftools/ffmpeg_mux_init.c | 17 +++++++----------
>  1 file changed, 7 insertions(+), 10 deletions(-)
> 
> diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
> index 8d475f5b45..c2867192ee 100644
> --- a/fftools/ffmpeg_mux_init.c
> +++ b/fftools/ffmpeg_mux_init.c
> @@ -661,11 +661,9 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o,
>          }
>          opt_match_per_stream_str(ost, &o->chroma_intra_matrices, oc, st, &chroma_intra_matrix);
>          if (chroma_intra_matrix) {
> -            uint16_t *p = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64);
> -            if (!p)
> +            if (!(video_enc->chroma_intra_matrix = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64)))

I heavily dislike assignments inside if().

Otherwise looks ok
diff mbox series

Patch

diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 8d475f5b45..c2867192ee 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -661,11 +661,9 @@  static int new_stream_video(Muxer *mux, const OptionsContext *o,
         }
         opt_match_per_stream_str(ost, &o->chroma_intra_matrices, oc, st, &chroma_intra_matrix);
         if (chroma_intra_matrix) {
-            uint16_t *p = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64);
-            if (!p)
+            if (!(video_enc->chroma_intra_matrix = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64)))
                 return AVERROR(ENOMEM);
-            video_enc->chroma_intra_matrix = p;
-            ret = parse_matrix_coeffs(ost, p, chroma_intra_matrix);
+            ret = parse_matrix_coeffs(ost, video_enc->chroma_intra_matrix, chroma_intra_matrix);
             if (ret < 0)
                 return ret;
         }
@@ -728,8 +726,8 @@  static int new_stream_video(Muxer *mux, const OptionsContext *o,
             FILE *f;
 
             /* compute this stream's global index */
-            for (int i = 0; i <= ost->file->index; i++)
-                ost_idx += output_files[i]->nb_streams;
+            for (int idx = 0; idx <= ost->file->index; idx++)
+                ost_idx += output_files[idx]->nb_streams;
 
             snprintf(logfilename, sizeof(logfilename), "%s-%d.log",
                      ost->logfile_prefix ? ost->logfile_prefix :
@@ -1145,21 +1143,20 @@  static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
         return AVERROR(ENOMEM);
 
     if (ost->enc_ctx) {
-        AVCodecContext *enc = ost->enc_ctx;
         AVIOContext *s = NULL;
         char *buf = NULL, *arg = NULL;
         const char *enc_stats_pre = NULL, *enc_stats_post = NULL, *mux_stats = NULL;
         const char *enc_time_base = NULL, *preset = NULL;
 
-        ret = filter_codec_opts(o->g->codec_opts, enc->codec_id,
-                                oc, st, enc->codec, &encoder_opts,
+        ret = filter_codec_opts(o->g->codec_opts, ost->enc_ctx->codec_id,
+                                oc, st, ost->enc_ctx->codec, &encoder_opts,
                                 &mux->enc_opts_used);
         if (ret < 0)
             goto fail;
 
         opt_match_per_stream_str(ost, &o->presets, oc, st, &preset);
         opt_match_per_stream_int(ost, &o->autoscale, oc, st, &autoscale);
-        if (preset && (!(ret = get_preset_file_2(preset, enc->codec->name, &s)))) {
+        if (preset && (!(ret = get_preset_file_2(preset, ost->enc_ctx->codec->name, &s)))) {
             AVBPrint bprint;
             av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED);
             do  {