From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 873334E16B for ; Fri, 6 Jun 2025 23:22:04 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 8DAE468C4F9; Sat, 7 Jun 2025 02:22:00 +0300 (EEST) Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 711E568C069 for ; Sat, 7 Jun 2025 02:21:54 +0300 (EEST) Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-70e3e0415a7so26470187b3.0 for ; Fri, 06 Jun 2025 16:21:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749252113; x=1749856913; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IFC4lN11QlJsMcuNJV2Lb5yfqBopGA+F2fJZPlfdXQQ=; b=fLYeMYvS9e5Cir1Y2VXo94uO9ohlXICnpVMY4Ims0v+TNeE55Y4m4M28MEl5mprVHp M5+eru5FtgAzjJTY/ENSw0f5/XWr6H3yaThqMu2Lx5lEwp3N6m4WhyUgRtQg2lIW1ZIg iHpkDI2wtaklXWTbBEHwsAVA7+L+NvI9fny/lTShH/S2+fqku/yJ0XhAsbKkpBca/VIP 4w7l9H/drJ/FyOgxdVXKAUU/ggrYWXBWFRsLLALEHAdffvD1x9Gl3nX8oIlmmsw3IEqg 8j00v+k2sfJgJ7n+BsPRkH/ryU8g4IrAuo6AuJwWIXoY9I76pMnmB3K8CkA93eSpUyy2 /G7Q== X-Gm-Message-State: AOJu0YxkD0e2a9iHQCuW3lxmVFZdszZgh7X6LbdE9HX0vkWKIwmMzEaL NDcPRGSbRAykkQ5bvQJRlOiGn+JBVtV32YFxZZsUqgHVvaf6ZcdkEQ7n2PEDyQxWeSHoXxPtmZQ FOCqLDHbmIdbIdMiNnYMDiU7tOyzmDv9mPw== X-Gm-Gg: ASbGncs+/Hbt0Ru+Pek8cmNzO0aCv06GXlzoHLP9pUfLXn9hT/1zvrM2RcVeQS5aGfl 3B9PwCsUZQ8UUPPRACiB3kDHUNc6WtutOKTqTYtGdV1E0c7UHTG5TD4rz1Bk9HDVGPXc1iqip4c vb95pTDYdv2qwjKHTRCzHWnaIQbE9RNZPy X-Google-Smtp-Source: AGHT+IEU6TyHMeHcVkYgJsa6JNBN0hjQbppN8ft1IOVYv4XAhqgnNBg8DVW7T5deo3doXk9NHCcg6cQgXJ/bYyOnTIg= X-Received: by 2002:a05:690c:a82:b0:70e:6c9c:e123 with SMTP id 00721157ae682-71108453f43mr9884257b3.0.1749252112840; Fri, 06 Jun 2025 16:21:52 -0700 (PDT) MIME-Version: 1.0 References: <20250606231220.88037-1-michael@niedermayer.cc> In-Reply-To: <20250606231220.88037-1-michael@niedermayer.cc> Date: Sat, 7 Jun 2025 00:21:43 +0100 X-Gm-Features: AX0GCFsDJme-nEpDq-uB1Nrrc9Yns2aepRi_d7dpMcmiWcrhlib-65hZ1HubF20 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: Re: [FFmpeg-devel] [PATCH] avformat/dhav: Do not evaluate avio_size() multiple times X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Kieran Kunhya via ffmpeg-devel Reply-To: FFmpeg development discussions and patches Cc: Kieran Kunhya , Justin Ruggles Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Sat, 7 Jun 2025, 00:12 Michael Niedermayer, wrote: > Code like FFMIN(MAX_DURATION_BUFFER_SIZE, avio_size(s->pb)) is not safe > as FFMIN() is a macro and avio_size() is thus evaluated multiple > times > > CC: Justin Ruggles > Signed-off-by: Michael Niedermayer > --- > libavformat/dhav.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/libavformat/dhav.c b/libavformat/dhav.c > index 5a83a8aea9d..c7e5371636a 100644 > --- a/libavformat/dhav.c > +++ b/libavformat/dhav.c > @@ -246,11 +246,12 @@ static int64_t get_duration(AVFormatContext *s) > int64_t end_buffer_pos; > int64_t offset; > unsigned date; > + int64_t size = avio_size(s->pb); > > if (!s->pb->seekable) > return 0; > > - if (start_pos + 16 > avio_size(s->pb)) > + if (start_pos + 16 > size) > return 0; > > avio_skip(s->pb, 16); > @@ -258,13 +259,13 @@ static int64_t get_duration(AVFormatContext *s) > get_timeinfo(date, &timeinfo); > start = av_timegm(&timeinfo) * 1000LL; > > - end_buffer_size = FFMIN(MAX_DURATION_BUFFER_SIZE, avio_size(s->pb)); > + end_buffer_size = FFMIN(MAX_DURATION_BUFFER_SIZE, size); > end_buffer = av_malloc(end_buffer_size); > if (!end_buffer) { > avio_seek(s->pb, start_pos, SEEK_SET); > return 0; > } > - end_buffer_pos = avio_size(s->pb) - end_buffer_size; > + end_buffer_pos = size - end_buffer_size; > avio_seek(s->pb, end_buffer_pos, SEEK_SET); > avio_read(s->pb, end_buffer, end_buffer_size); > > -- > 2.49.0 > Can you explain what "not safe" means? I assume it means avio_size() causes a seek to the end to get the length but it's not obvious. Kieran > _______________________________________________ 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".