From d67335699028b0c61f31eaf484f64ea5edd21abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sat, 30 Nov 2024 06:39:49 +0100 Subject: [PATCH] common: ensure MP_HANDLE_OOM is used only on pointers To make it clear it should be used for memory allocation and not generic error checking. --- audio/decode/ad_lavc.c | 4 +++- common/common.h | 5 +++-- common/encode_lavc.c | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c index d99aa061c6812..2a46b8fad103d 100644 --- a/audio/decode/ad_lavc.c +++ b/audio/decode/ad_lavc.c @@ -100,9 +100,11 @@ static bool init(struct mp_filter *da, struct mp_codec_params *codec, } ctx->avctx = avcodec_alloc_context3(lavc_codec); + MP_HANDLE_OOM(ctx->avctx); ctx->avframe = av_frame_alloc(); + MP_HANDLE_OOM(ctx->avframe); ctx->avpkt = av_packet_alloc(); - MP_HANDLE_OOM(ctx->avctx && ctx->avframe && ctx->avpkt); + MP_HANDLE_OOM(ctx->avpkt); ctx->avctx->codec_type = AVMEDIA_TYPE_AUDIO; ctx->avctx->codec_id = lavc_codec->id; ctx->avctx->pkt_timebase = ctx->codec_timebase; diff --git a/common/common.h b/common/common.h index 7466ea2d610b9..c90f44402d791 100644 --- a/common/common.h +++ b/common/common.h @@ -166,8 +166,9 @@ char **mp_dup_str_array(void *tctx, char **s); // This macro generally behaves like an assert(), except it will make sure to // kill the process even with NDEBUG. #define MP_HANDLE_OOM(x) do { \ - assert(x); \ - if (!(x)) \ + void *oom_p_ = (x); \ + assert(oom_p_); \ + if (!oom_p_) \ abort(); \ } while (0) diff --git a/common/encode_lavc.c b/common/encode_lavc.c index 0e94c0a4d8278..0e734636a179f 100644 --- a/common/encode_lavc.c +++ b/common/encode_lavc.c @@ -372,7 +372,7 @@ static void encode_lavc_add_stream(struct encoder_context *enc, dst->st->sample_aspect_ratio = info->codecpar->sample_aspect_ratio; if (avcodec_parameters_copy(dst->st->codecpar, info->codecpar) < 0) - MP_HANDLE_OOM(0); + MP_HANDLE_OOM(NULL); dst->on_ready = on_ready; dst->on_ready_ctx = on_ready_ctx;