From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id AEAB742F42 for ; Wed, 14 Sep 2022 10:45:08 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 17F6068BAAA; Wed, 14 Sep 2022 13:45:05 +0300 (EEST) Received: from mail-yw1-f170.google.com (mail-yw1-f170.google.com [209.85.128.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A9EC868B7D4 for ; Wed, 14 Sep 2022 13:44:58 +0300 (EEST) Received: by mail-yw1-f170.google.com with SMTP id 00721157ae682-333a4a5d495so174580827b3.10 for ; Wed, 14 Sep 2022 03:44:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date; bh=cIeFleIDKRIvwSgdEjFfjkDMta0Wj2EDS4NuM1xfSa4=; b=ONHtGBXI+Va6NHp9Ur2p42noZGemI4hKB7xd+iHHQR5Qmznv3H2oxnWgBI0DNOkfeH Z9/fUzAkSr7akHZsvPisBcKR8dzyHcu3X4tLQmhLmpICNxFRbziEE43yO7My4Sb8f9SB 0lCfLjpgpyOwev+IKLCGCnfsYd/bLz7MdEOxYpf18MpjJrR0unKxeBcx+RuofVeQ7OW+ DR6HzIjqSZr+WE3bA3TvqTVheHsrLzjNMRdR3pBijrF/WQb6EC1ny+vBqLQkfFo/I6wv +R3wbbZ1Qw+sL9ZU3MxZr4KJCu+vsGR7bZfUkAL4YBFiqow5Ozna13L33wlV3f2jq08W He1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=cIeFleIDKRIvwSgdEjFfjkDMta0Wj2EDS4NuM1xfSa4=; b=TT2WYXmaL6OY2EfvbjcqwbNb/PQ6FSmdHbPaUOh6WHQz8TmtShf4u4VvE9u5tA6oS7 56lLYb1UvEfFQTKjeY/m6AWTPI5nxQ2H/OHNEvowj1KW+IVlueEu2N5yYjshzNFzPRzH cbSnExAcR3wZFvRdqt8HIKx+GkxYiNaNhcjXrSQS9eqmzweApY1INZWH2u2yLD0gQG3H 7y0bXiiFQ+IqyeNKhDF2At15mPzJh+OB2jM4bksyVZhF/r9JwcAeTY9pi688xYa2nxY5 gbb/BzCe8tuvgvHN5ROcRRf4RI+LHhuOhN2oSb/NNvjD6b5xDG16kAckY9cbdMdqVDRx DPfg== X-Gm-Message-State: ACgBeo1OqJV5oLXHf23wplQwSSY9O5SKYS7S5SyQJpz7z4hz3xeaknq2 JEbCvhvajcF7+xiY5cwfWs05/Tv2RWOeeBygnD1I1f1O X-Google-Smtp-Source: AA6agR4Mc8veJxqRis4ltlJNdcKC9uRZHlVBTdd0n3mP2CLQePiqaZ1rDIxq8C3pHFs2TzYlXKcOFV8+lshWIfa9bkU= X-Received: by 2002:a81:4e4e:0:b0:348:8a78:9905 with SMTP id c75-20020a814e4e000000b003488a789905mr25085341ywb.40.1663152297261; Wed, 14 Sep 2022 03:44:57 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a81:7402:0:0:0:0:0 with HTTP; Wed, 14 Sep 2022 03:44:56 -0700 (PDT) In-Reply-To: References: From: Paul B Mahol Date: Wed, 14 Sep 2022 12:44:56 +0200 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH] avformat/dump: Avoid unnecessary implicit calculation of strlen 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: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt 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 9/14/22, Andreas Rheinhardt wrote: > av_strlcpy() returns the length of the src string to enable > the caller to check for truncation. It is currently used in > the following way in dump_metadata(): Every metadata value > is searched for \b, \n, \v, \f, \r and then the data up to > the first of these characters found is copied to a small > temporary buffer via av_strlcpy() (but of course not more > than fits into said buffer) and then printed; all characters up > to the character found earlier are then treated as consumed. > > But this is bad performance-wise if the while string is big > and contains many of these characters, because av_strlcpy() > will unnecessarily calculate the length of the whole remaining string. > (dump_metadata() actually ignored the return value of av_strlcpy().) > > Fix this by just not copying the data in a temporary buffer at all. > Instead just use the %.*s to bound the number of characters output. > > Signed-off-by: Andreas Rheinhardt > --- > libavformat/dump.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/libavformat/dump.c b/libavformat/dump.c > index e3f0056c20..cafcef36c6 100644 > --- a/libavformat/dump.c > +++ b/libavformat/dump.c > @@ -145,10 +145,8 @@ static void dump_metadata(void *ctx, const AVDictionary > *m, const char *indent) > av_log(ctx, AV_LOG_INFO, > "%s %-16s: ", indent, tag->key); > while (*p) { > - char tmp[256]; > size_t len = strcspn(p, "\x8\xa\xb\xc\xd"); > - av_strlcpy(tmp, p, FFMIN(sizeof(tmp), len+1)); > - av_log(ctx, AV_LOG_INFO, "%s", tmp); > + av_log(ctx, AV_LOG_INFO, "%.*s", (int)(FFMIN(255, > len)), p); > p += len; > if (*p == 0xd) av_log(ctx, AV_LOG_INFO, " "); > if (*p == 0xa) av_log(ctx, AV_LOG_INFO, "\n%s %-16s: > ", indent, ""); > -- > 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". > LGTM _______________________________________________ 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".