From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTPS id A4B9E4D285
	for <ffmpegdev@gitmailbox.com>; Wed, 16 Apr 2025 11:33:37 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 709E7687DEC;
	Wed, 16 Apr 2025 14:33:33 +0300 (EEST)
Received: from NAM10-BN7-obe.outbound.protection.outlook.com
 (mail-bn7nam10olkn2036.outbound.protection.outlook.com [40.92.40.36])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C201E687A19
 for <ffmpeg-devel@ffmpeg.org>; Wed, 16 Apr 2025 14:33:26 +0300 (EEST)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
 b=e3W2id7VbBPfI5TxC+6EfaciJ7mSGN+f77MVSZCxcbroa5y/EfS1wkuOXL/vrGgUvedKxAnOyH1pthwjN51SnHVi8b+gfP/QYzOrDygjkfB4vkdmcbRRhm0RIU4pkDSQdKwl1NP0+wm3HGgPdm3yZL6t+9azmL5pNLNiXUIslhatF1FSnS3gRGk++MN1jh3cw5+ohvoRSi5+TRP6687s4v7q1Ok80NXajBH5VKbzY26AQEpZJWOCPFHN7usz+R8a+W6PQITBFVDSRXwPd78LNTJfP1hr4Usj9AIl3ZULigegJYDpmgo+joHUG+hJCoFwDOwcOvO+adtlnGgUZIPnYw==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; 
 s=arcselector10001;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
 bh=j7otpD6jfXQv0q0L4OVObNWMcvxguRRMBtVWFiuWgzA=;
 b=yQDI9WZ7vYqUXMDvR7K/lq0Fdp+/sOry3KURTo9JGmH+feWDsCXu+FAsddUExUG9F5hiRI2jQJJ2fWKA86XqIgqEwncMpRx92UVvK/2gTHqOgau98QSO+o0BVOXxIJtxt1ticPISXnOOqRqUv3LAt4rEtE32pgo4N6MrbuXDxGNMveAR5CTnWw3+8TB9CebAMhuDrDMR99wPm3IAuZX57jLNnU5EIHXXlgvW2p+WF5FJqnbp/OkzlRjCzmwa2FLW/OztwqmbFFa3WXtfRkyJIu6j7CRKgsPX4EOL+bQgwfaLlZfcCPW9XgVHw9phJPyP1nOCvw0CEk2zhV69NT4z8A==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none;
 dkim=none; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com;
 s=selector1;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=j7otpD6jfXQv0q0L4OVObNWMcvxguRRMBtVWFiuWgzA=;
 b=YaXjpRJ1SYCBWDbjzJXAX1eetziGMiKdKON54J6WnyjuygWj8bEkZuyxSNH4ybBtbspC2ztZ7vlE234md2hZc3A1+bOilvBrpRMtm2S0YmjL5PgrRKbm5VIR2OkS1roRFm4ycdA+gLofOkAYxDunuXV9kQG9kjpZaFFX8y/hqc6MueX4zvXUC8p9+UP005pkYGvbeIIKIMn4WfRwWD1VBULy+hEWN2Hq+VN/w6FpEFO+hfC6iDK1Xt6HnaEj79Qwuke+W+/0cOm7GH8s6uRiGwW+yXD7CdnxUu5nPu5JyQTOa53ScSQLufoPEFQZercN+Aq/CEN4FPv9PZ7d81BqhA==
Received: from CH0P223MB0363.NAMP223.PROD.OUTLOOK.COM (2603:10b6:610:e8::16)
 by CH0P223MB0153.NAMP223.PROD.OUTLOOK.COM (2603:10b6:610:f5::16) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.21; Wed, 16 Apr
 2025 11:33:23 +0000
Received: from CH0P223MB0363.NAMP223.PROD.OUTLOOK.COM
 ([fe80::1c4f:8a7e:d292:81bc]) by CH0P223MB0363.NAMP223.PROD.OUTLOOK.COM
 ([fe80::1c4f:8a7e:d292:81bc%3]) with mapi id 15.20.8632.036; Wed, 16 Apr 2025
 11:33:23 +0000
From: "softworkz ." <softworkz-at-hotmail.com@ffmpeg.org>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Thread-Topic: [FFmpeg-devel] [PATCH v2 02/10] fftools/textformat: Quality
 improvements
Thread-Index: AQHbrrgW9R6AVB6Btked3yEOin54GrOmHO4AgAAHeCA=
Date: Wed, 16 Apr 2025 11:33:23 +0000
Message-ID: <CH0P223MB0363BF1B89B56D5E8AD9E695BABD2@CH0P223MB0363.NAMP223.PROD.OUTLOOK.COM>
References: <pull.66.ffstaging.FFmpeg.1744634826.ffmpegagent@gmail.com>
 <pull.66.v2.ffstaging.FFmpeg.1744798340.ffmpegagent@gmail.com>
 <6568269678c770544d58a9277feaf4953c352d9d.1744798340.git.ffmpegagent@gmail.com>
 <GV1P250MB07371D91FE8825EFAB6DA6C08FBD2@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM>
In-Reply-To: <GV1P250MB07371D91FE8825EFAB6DA6C08FBD2@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
x-ms-publictraffictype: Email
x-ms-traffictypediagnostic: CH0P223MB0363:EE_|CH0P223MB0153:EE_
x-ms-office365-filtering-correlation-id: 20c003b1-1794-48a8-2009-08dd7cda7f09
x-ms-exchange-slblob-mailprops: YfhX3sd/0TWYnBBcTvvGLlHdY79wcCjU/1DNHepxCFNl40ngVBnJ6RJputTODFbWlaFrQhvmq9X6jqQB3o/llk/bq0dDp1NRdJCChzcSoToQI9Oyn0dBbYXRC3xgQo+za/iyuMrhbs7NDYv5yCxqBQwQrMPF4+9PQDmkORrZ5kp0+tEkLQrdzfZkSK6DpbHlyJ4dl97VrwyUbuel2aE+5onJpHbjqlNOC2SQwCsMp3xKN8gzEYg4qJf9anM57B7RUlVZ0SwpvQtGhTMyHbdEIXuygyn4+UAHvraNQvaxMBe+Aytf238RVjGoTkCGs5pvM+hFHUC8JCb/m7CvmFKqn4910ssuMLcc8Hj80pbHks1miupa9LTpdyb1UHB7n/Lx4EKOZL5BVPGf09LcREUM9Eud+qfQKv3cVdu/hR0qihMp/I6LD5ZgQdCNV8dOk0j0RgbB+bg1eKylu9HD8IlLwo5ihjCRGX9X0dfGMrnBHT1UtQuw9EzlSWPEWvs+CeSEkv8Pkz3CgXoRtdKQwa/+bn4GVZ7xSsgtq0s0BsrY1lZHA71DQEo5XG7zjme79XVcx9RhiOWXmv7+nU8HqDjOkyrXJumFv3ElQhmej6PHoxXYmNq0uWWtpNysnjLb3eXwoXlJMkN7kB8p5BVpkOjnAXNy02gD0d7VKplHarS6CQIe8FwOAh6ifWlsRfJ7C4WLQ2ukVxQAcVw1WmCiYBxuNmH0Drm6R0V9jYTKdiWa8ICe7tFfb5SOkSSC7vaQHsGyH8nxBPFS9gMjx2HZhXAGVuEdWbhj+zNo5HTJ8a+UiCI=
x-microsoft-antispam: BCL:0;
 ARA:14566002|19110799003|8060799006|8062599003|7092599003|15080799006|461199028|10035399004|440099028|3412199025|41001999003|102099032;
x-microsoft-antispam-message-info: =?us-ascii?Q?XeBXCdTBU+6Mad4QOPx3CwF9Q/yuaJzlDS9yWw5AP+NHJuxvToqN4o/BYvw/?=
 =?us-ascii?Q?lzfbrXiG/+/PagVZXl4LsHtHBjxaM+lhXLOr7HJ3Ge0mUXK4e0uzH27UvMQg?=
 =?us-ascii?Q?xn6KbqrFzQQ3q9chKAqEHWDzXaMiLpIn2lr1d8mYgc37dGdULIY2jYD5/sOv?=
 =?us-ascii?Q?pmSe1YqqHJhpeGFxH1MrP+s4mNtnGytD1sX24XLnmiPvaDndAJltc25X5lXT?=
 =?us-ascii?Q?HLba4qJvd63CVXVSRAqKXijjPIvGXr4ptCcD3JQ9G56GQ/iPcIO5dDb1wRTI?=
 =?us-ascii?Q?n5iBrNTZ6XsIYVRybFX8PX7qO7XNmLgnTWGwFCwwL04lZze/Bh1h34Zp+axG?=
 =?us-ascii?Q?t+f9CCwrKrX7w9duQ1wi2kLKwdVGSU6NkseFKn/fa3dnsPEuxj9y5B5AfuEn?=
 =?us-ascii?Q?18MgcEajUksPF/SLjulqqEgbcfFyWcoTWL8AUYV3h73cSpIpEwjF5VtxYInW?=
 =?us-ascii?Q?UQ+DvW9xbJrWWVxPneHc+RFrxvq3pRjEE0gIkAL3rFfdDW3zbuqhGhuqrHpv?=
 =?us-ascii?Q?EGjhy5fIQ7b4VQ4z1VblgViQYfmwCCunINAsAxQIOR6a+zoNu+UVlUUXHjTk?=
 =?us-ascii?Q?yOtfzMwdG3pWWxNpErN2y1jMNTY6vhb4HHTxrDUe11bguH/MqAtIvnV/apia?=
 =?us-ascii?Q?erk/rk+bcmeFhWfleXPKhHwJKJBRv5mwKylANdjHA3CJZqT/gq09PmSn9PjY?=
 =?us-ascii?Q?sufJoZrAzeaY0ZbX0SQCdlM+pbpuupXIsU+TJoO0tfnLkRH+mwdJQgi0mXxT?=
 =?us-ascii?Q?5sdrhGhiTkSsk/BEWiQgRbn2GJIP6QJdWcHqu8k1/lvaBITLMB371LdXVt6m?=
 =?us-ascii?Q?c/LZfkekpAK3kHo2GT08QCpc1WWhQYRMF2qNQl5nsCK25VcCJnM604qSwXuf?=
 =?us-ascii?Q?KJVtaMHCy8C0twqcYkYY7Lau43v4sgbb7hFkZQ3o78TzS2vQPo2Wd6Q3X5uZ?=
 =?us-ascii?Q?8Qh7Vzprv5lTQgfY505WbnmXV6yYqBUZKBvHao7nBfdg5twuVriuuF3+LABY?=
 =?us-ascii?Q?6nvwh4lKTHTX0VZrmSqRpMetOqWstOQanty6tkbAKUIL2GKR5cst3UxM+YjC?=
 =?us-ascii?Q?O2DpbSIX0W9UpO+yRy8MLTLfOeZICoiGAws8sqHsPOtKUvXoqlMOa/+iukBn?=
 =?us-ascii?Q?ZO99i09VKL7dWra3AT4kgNbuOS88H5gDsF6n6gvwELCL37egO9DQYmwL6rSQ?=
 =?us-ascii?Q?bNOH2YPZY676nCTB?=
x-ms-exchange-antispam-messagedata-chunkcount: 1
x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?g0Hfgk5q36GiqFCYKnxOXp73JU9BO4mfQbpxmtyydEogmfknpclN+BLAfglN?=
 =?us-ascii?Q?OsC4CBrW5X5bF8rlpEIUCAAEvvOEaCbyzB7odGyElGlJrWSl1oBhx1fkIpPe?=
 =?us-ascii?Q?MZBoZGpmQsulvCjWLKys+2KV2Ko8PrDo+F2d/4ZDJuSPqilK2UiwUX25CggY?=
 =?us-ascii?Q?kcdyA9KHzmdzGzD75E+Ce953jZ7MEjydf1XW2DeEbJWzkyuEr/9E8wgtxyqZ?=
 =?us-ascii?Q?YKpULkz1YAdA5M5cxRpLN5JBZKdPAkJfWDz+53ypnh6Darbh/sSWD/I1eXn7?=
 =?us-ascii?Q?DfR+BEbkxepL+yN/ZnSn3X0gINrX2aF7IiebaMdzzD60HgulQ2pAzkYWvoFn?=
 =?us-ascii?Q?YBb75ITCBhQSRLKaY/RuN8B99eWUffpo624nLhwREDk6QP4hEtrbcapiDG+Z?=
 =?us-ascii?Q?HSfjvWhGU2+7jJIFO88TZfvzEnol3TOwW9ejGKAFM3RGN5q47mNjrMq5wrMI?=
 =?us-ascii?Q?AF2OeGiE0mEtmcdQDqQDjvlPnGZUiL9UODS3nhI5eUNXnX8aAVIH8jtFckHL?=
 =?us-ascii?Q?sgdP1Jdq/SWnPlw6kKX3ygnSrYZ2GHf3Gnz8f4a7pGizP0TNZMOdYmTzalwF?=
 =?us-ascii?Q?daB19S2NFpf0xibdjbzTvWQp11gvggtBWpd84WLsG4RDWQtfN8UYHcPp/mtN?=
 =?us-ascii?Q?Awl5nVaydhMFQjOsr31kNvCU60uUgp1JEjHT/FB3CdED81RMCbkd1WpUtByr?=
 =?us-ascii?Q?pe+6GwTBerjPbgSbwtK1vvLFf2vPs3qgUxbaMwHSeIOeYMKIRaS2/E75b/Rm?=
 =?us-ascii?Q?44sxAdZnt5r4hx/HeX9noMgAGbPUpfH5h7LpnLNG679cell1JrsIl3rn6Jiy?=
 =?us-ascii?Q?GnNgGVbC71kelKxuZMz3w5D2i4WktcW+BmSusr/VM9p6/yiGgEmZYkI8x6gd?=
 =?us-ascii?Q?27lKShV7IJjbfP+nytX6Li3y97fQRA2sPN6X1pvUn+61MhdspWOxBbCaeEor?=
 =?us-ascii?Q?C4nZNag9e0RKlyxVMcbEzCBwQlFOyueFPck9oHS+wQ/ANXv0gRmxx1n8SejU?=
 =?us-ascii?Q?i42cODYtUoRURmw9WO8oUzcAc8sZuLrQBNivAqsDc5a4dTrWElhL9X6b9mN0?=
 =?us-ascii?Q?nzWI4LJDs7kyI7vz3Vb/GR6tLbzNzk/8RSe5+Ejza99tkB5gIQqqId+cTdPs?=
 =?us-ascii?Q?8+Fd/2GkhWjbg8yoH7IRyj1XLYgEDjuHhmgSZupw3FsBJBC8h53t2L6pMlRi?=
 =?us-ascii?Q?U3czGyWLMlB/YeWFqkgFRm1w47v9bi4JlR0woKV0OzsSVZqZhnV8jaWICMY?=
 =?us-ascii?Q?=3D?=
MIME-Version: 1.0
X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-1ff67.templateTenant
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: CH0P223MB0363.NAMP223.PROD.OUTLOOK.COM
X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000
X-MS-Exchange-CrossTenant-Network-Message-Id: 20c003b1-1794-48a8-2009-08dd7cda7f09
X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Apr 2025 11:33:23.2476 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa
X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000
X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0P223MB0153
Subject: Re: [FFmpeg-devel] [PATCH v2 02/10] fftools/textformat: Quality
 improvements
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/CH0P223MB0363BF1B89B56D5E8AD9E695BABD2@CH0P223MB0363.NAMP223.PROD.OUTLOOK.COM/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>



> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Andreas Rheinhardt
> Sent: Mittwoch, 16. April 2025 12:49
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH v2 02/10] fftools/textformat:
> Quality improvements
> 
> softworkz:
> > From: softworkz <softworkz@hotmail.com>
> >
> > Signed-off-by: softworkz <softworkz@hotmail.com>
> > ---
> >  fftools/textformat/avtextformat.c | 111 +++++++++++++++++++--------
> ---
> >  fftools/textformat/avtextformat.h |   6 +-
> >  fftools/textformat/tf_default.c   |   8 ++-
> >  fftools/textformat/tf_ini.c       |   2 +-
> >  fftools/textformat/tf_json.c      |   8 ++-
> >  fftools/textformat/tf_xml.c       |   3 -
> >  fftools/textformat/tw_avio.c      |   9 ++-
> >  7 files changed, 93 insertions(+), 54 deletions(-)
> >
> > diff --git a/fftools/textformat/avtextformat.c
> b/fftools/textformat/avtextformat.c
> > index 811b14b999..4c8def8e65 100644
> > --- a/fftools/textformat/avtextformat.c
> > +++ b/fftools/textformat/avtextformat.c
> > @@ -93,9 +93,8 @@ static const AVClass textcontext_class = {
> >
> >  static void bprint_bytes(AVBPrint *bp, const uint8_t *ubuf, size_t
> ubuf_size)
> >  {
> > -    int i;
> >      av_bprintf(bp, "0X");
> > -    for (i = 0; i < ubuf_size; i++)
> > +    for (unsigned i = 0; i < ubuf_size; i++)
> >          av_bprintf(bp, "%02X", ubuf[i]);
> >  }
> >
> > @@ -141,7 +140,10 @@ int avtext_context_open(AVTextFormatContext
> **ptctx,
> >      AVTextFormatContext *tctx;
> >      int i, ret = 0;
> >
> > -    if (!(tctx = av_mallocz(sizeof(AVTextFormatContext)))) {
> > +    if (!ptctx || !formatter)
> > +        return AVERROR(EINVAL);
> > +
> > +    if (!((tctx = av_mallocz(sizeof(AVTextFormatContext))))) {
> >          ret = AVERROR(ENOMEM);
> >          goto fail;
> >      }
> > @@ -213,25 +215,26 @@ int avtext_context_open(AVTextFormatContext
> **ptctx,
> >                      av_log(NULL, AV_LOG_ERROR, " %s", n);
> >                  av_log(NULL, AV_LOG_ERROR, "\n");
> >              }
> > -            return ret;
> > +            goto fail;
> >          }
> >
> >      /* validate replace string */
> >      {
> > -        const uint8_t *p = tctx->string_validation_replacement;
> > -        const uint8_t *endp = p + strlen(p);
> > +        const uint8_t *p = (uint8_t *)tctx-
> >string_validation_replacement;
> > +        const uint8_t *endp = p + strlen((const char *)p);
> 
> We use -Wno-pointer-sign in order to avoid these ugly casts.

Yep, I know. Since I'm not a C-for-life developer, I'm using and 
taking attention of warnings and hints like clang-tidy.
When you have a file with dozens of warnings these things are not
helpful, because you cannot go through all of them a hundred times.
When disabling certain warnings altogether, nothing is won, because
often there's one in ten cases where the it hints at a problem while
all others are harmless. 
In order to get rid of a warning, you can either add ugly comments 
or - the designated way from the compiler side is to be explicit by
e.g. making explicit casts. That's why you see them at some places.
Doing so, improves quality when working - even for languages that 
I know in a similar way like you know C.

If we could agree to remove these in a future commit, it would be 
great. Otherwise, I can drop them right now as well.


> 
> >          while (*p) {
> >              const uint8_t *p0 = p;
> >              int32_t code;
> >              ret = av_utf8_decode(&code, &p, endp, tctx-
> >string_validation_utf8_flags);
> >              if (ret < 0) {
> >                  AVBPrint bp;
> > -                av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
> > +                av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
> >                  bprint_bytes(&bp, p0, p - p0),
> >                      av_log(tctx, AV_LOG_ERROR,
> >                             "Invalid UTF8 sequence %s found in
> string validation replace '%s'\n",
> >                             bp.str, tctx-
> >string_validation_replacement);
> > -                return ret;
> > +                av_bprint_finalize(&bp, NULL);
> 
> You know that this is supposed to be for a single UTF-8 code point? It
> is not supposed to write hundreds of bytes (although this may happen
> with crazy input).
> 
> > +                goto fail;
> >              }
> >          }
> >      }
> > @@ -259,6 +262,9 @@ static const char unit_bit_per_second_str[] =
> "bit/s";
> >
> >  void avtext_print_section_header(AVTextFormatContext *tctx, const
> void *data, int section_id)
> >  {
> > +    if (section_id < 0 || section_id >= tctx->nb_sections)
> > +        return;
> > +
> >      tctx->level++;
> >      av_assert0(tctx->level < SECTION_MAX_NB_LEVELS);
> >
> > @@ -272,6 +278,9 @@ void
> avtext_print_section_header(AVTextFormatContext *tctx, const void
> *data, in
> >
> >  void avtext_print_section_footer(AVTextFormatContext *tctx)
> >  {
> > +    if (tctx->level < 0 || tctx->level >= SECTION_MAX_NB_LEVELS)
> > +        return;
> > +
> >      int section_id = tctx->section[tctx->level]->id;
> >      int parent_section_id = tctx->level
> >          ? tctx->section[tctx->level - 1]->id
> > @@ -289,7 +298,12 @@ void
> avtext_print_section_footer(AVTextFormatContext *tctx)
> >
> >  void avtext_print_integer(AVTextFormatContext *tctx, const char
> *key, int64_t val)
> >  {
> > -    const struct AVTextFormatSection *section = tctx->section[tctx-
> >level];
> > +    const AVTextFormatSection *section;
> > +
> > +    if (!key || tctx->level < 0 || tctx->level >=
> SECTION_MAX_NB_LEVELS)
> > +        return;
> > +
> > +    section = tctx->section[tctx->level];
> >
> >      if (section->show_all_entries || av_dict_get(section-
> >entries_to_show, key, NULL, 0)) {
> >          tctx->formatter->print_integer(tctx, key, val);
> > @@ -299,24 +313,25 @@ void avtext_print_integer(AVTextFormatContext
> *tctx, const char *key, int64_t va
> >
> >  static inline int validate_string(AVTextFormatContext *tctx, char
> **dstp, const char *src)
> >  {
> > -    const uint8_t *p, *endp;
> > +    const uint8_t *p, *endp, *srcp = (const uint8_t *)src;
> >      AVBPrint dstbuf;
> > +    AVBPrint bp;
> >      int invalid_chars_nb = 0, ret = 0;
> >
> > +    *dstp = NULL;
> >      av_bprint_init(&dstbuf, 0, AV_BPRINT_SIZE_UNLIMITED);
> > +    av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
> >
> > -    endp = src + strlen(src);
> > -    for (p = src; *p;) {
> > -        uint32_t code;
> > +    endp = srcp + strlen(src);
> > +    for (p = srcp; *p;) {
> > +        int32_t code;
> >          int invalid = 0;
> >          const uint8_t *p0 = p;
> >
> >          if (av_utf8_decode(&code, &p, endp, tctx-
> >string_validation_utf8_flags) < 0) {
> > -            AVBPrint bp;
> > -            av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
> > -            bprint_bytes(&bp, p0, p-p0);
> > -            av_log(tctx, AV_LOG_DEBUG,
> > -                   "Invalid UTF-8 sequence %s found in string
> '%s'\n", bp.str, src);
> > +            av_bprint_clear(&bp);
> > +            bprint_bytes(&bp, p0, p - p0);
> > +            av_log(tctx, AV_LOG_DEBUG, "Invalid UTF-8 sequence %s
> found in string '%s'\n", bp.str, src);
> >              invalid = 1;
> >          }
> >
> > @@ -336,7 +351,7 @@ static inline int
> validate_string(AVTextFormatContext *tctx, char **dstp, const
> >          }
> >
> >          if (!invalid || tctx->string_validation ==
> AV_TEXTFORMAT_STRING_VALIDATION_IGNORE)
> > -            av_bprint_append_data(&dstbuf, p0, p-p0);
> > +            av_bprint_append_data(&dstbuf, (const char *)p0, p -
> p0);
> >      }
> >
> >      if (invalid_chars_nb && tctx->string_validation ==
> AV_TEXTFORMAT_STRING_VALIDATION_REPLACE)
> > @@ -346,6 +361,7 @@ static inline int
> validate_string(AVTextFormatContext *tctx, char **dstp, const
> >
> >  end:
> >      av_bprint_finalize(&dstbuf, dstp);
> > +    av_bprint_finalize(&bp, NULL);
> >      return ret;
> >  }
> >
> > @@ -358,17 +374,18 @@ struct unit_value {
> >      const char *unit;
> >  };
> >
> > -static char *value_string(AVTextFormatContext *tctx, char *buf, int
> buf_size, struct unit_value uv)
> > +static char *value_string(const AVTextFormatContext *tctx, char
> *buf, int buf_size, struct unit_value uv)
> >  {
> >      double vald;
> > -    int64_t vali;
> > +    int64_t vali = 0;
> >      int show_float = 0;
> >
> >      if (uv.unit == unit_second_str) {
> >          vald = uv.val.d;
> >          show_float = 1;
> >      } else {
> > -        vald = vali = uv.val.i;
> > +        vald = (double)uv.val.i;
> > +        vali = uv.val.i;
> >      }
> >
> >      if (uv.unit == unit_second_str && tctx-
> >use_value_sexagesimal_format) {
> > @@ -387,17 +404,17 @@ static char *value_string(AVTextFormatContext
> *tctx, char *buf, int buf_size, st
> >              int64_t index;
> >
> >              if (uv.unit == unit_byte_str && tctx-
> >use_byte_value_binary_prefix) {
> > -                index = (int64_t) (log2(vald)) / 10;
> > -                index = av_clip(index, 0,
> FF_ARRAY_ELEMS(si_prefixes) - 1);
> > +                index = (int64_t)(log2(vald) / 10);
> > +                index = av_clip64(index, 0,
> FF_ARRAY_ELEMS(si_prefixes) - 1);
> >                  vald /= si_prefixes[index].bin_val;
> >                  prefix_string = si_prefixes[index].bin_str;
> >              } else {
> > -                index = (int64_t) (log10(vald)) / 3;
> > -                index = av_clip(index, 0,
> FF_ARRAY_ELEMS(si_prefixes) - 1);
> > +                index = (int64_t)(log10(vald) / 3);
> > +                index = av_clip64(index, 0,
> FF_ARRAY_ELEMS(si_prefixes) - 1);
> >                  vald /= si_prefixes[index].dec_val;
> >                  prefix_string = si_prefixes[index].dec_str;
> >              }
> > -            vali = vald;
> > +            vali = (int64_t)vald;
> >          }
> >
> >          if (show_float || (tctx->use_value_prefix && vald !=
> (int64_t)vald))
> > @@ -425,9 +442,14 @@ void avtext_print_unit_int(AVTextFormatContext
> *tctx, const char *key, int value
> >
> >  int avtext_print_string(AVTextFormatContext *tctx, const char *key,
> const char *val, int flags)
> >  {
> > -    const struct AVTextFormatSection *section = tctx->section[tctx-
> >level];
> > +    const AVTextFormatSection *section;
> >      int ret = 0;
> >
> > +    if (!key || !val || tctx->level < 0 || tctx->level >=
> SECTION_MAX_NB_LEVELS)
> > +        return AVERROR(EINVAL);
> > +
> > +    section = tctx->section[tctx->level];
> > +
> >      if (tctx->show_optional_fields == SHOW_OPTIONAL_FIELDS_NEVER ||
> >          (tctx->show_optional_fields == SHOW_OPTIONAL_FIELDS_AUTO
> >              && (flags & AV_TEXTFORMAT_PRINT_STRING_OPTIONAL)
> > @@ -469,12 +491,11 @@ void avtext_print_rational(AVTextFormatContext
> *tctx, const char *key, AVRationa
> >  void avtext_print_time(AVTextFormatContext *tctx, const char *key,
> >                         int64_t ts, const AVRational *time_base, int
> is_duration)
> >  {
> > -    char buf[128];
> > -
> >      if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration &&
> ts == 0)) {
> >          avtext_print_string(tctx, key, "N/A",
> AV_TEXTFORMAT_PRINT_STRING_OPTIONAL);
> >      } else {
> > -        double d = ts * av_q2d(*time_base);
> > +        char buf[128];
> > +        double d = av_q2d(*time_base) * ts;
> >          struct unit_value uv;
> >          uv.val.d = d;
> >          uv.unit = unit_second_str;
> > @@ -495,7 +516,8 @@ void avtext_print_data(AVTextFormatContext
> *tctx, const char *name,
> >                         const uint8_t *data, int size)
> >  {
> >      AVBPrint bp;
> > -    int offset = 0, l, i;
> > +    unsigned offset = 0;
> > +    int l, i;
> >
> >      av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
> >      av_bprintf(&bp, "\n");
> > @@ -522,25 +544,29 @@ void avtext_print_data(AVTextFormatContext
> *tctx, const char *name,
> >  void avtext_print_data_hash(AVTextFormatContext *tctx, const char
> *name,
> >                              const uint8_t *data, int size)
> >  {
> > -    char *p, buf[AV_HASH_MAX_SIZE * 2 + 64] = { 0 };
> > +    char buf[AV_HASH_MAX_SIZE * 2 + 64] = { 0 };
> > +    int len;
> >
> >      if (!tctx->hash)
> >          return;
> >
> >      av_hash_init(tctx->hash);
> >      av_hash_update(tctx->hash, data, size);
> > -    snprintf(buf, sizeof(buf), "%s:", av_hash_get_name(tctx-
> >hash));
> > -    p = buf + strlen(buf);
> > -    av_hash_final_hex(tctx->hash, p, buf + sizeof(buf) - p);
> > +    len = snprintf(buf, sizeof(buf), "%s:", av_hash_get_name(tctx-
> >hash));
> > +    av_hash_final_hex(tctx->hash, (uint8_t *)&buf[len],
> (int)sizeof(buf) - len);
> >      avtext_print_string(tctx, name, buf, 0);
> >  }
> >
> >  void avtext_print_integers(AVTextFormatContext *tctx, const char
> *name,
> > -                                  uint8_t *data, int size, const
> char *format,
> > -                                  int columns, int bytes, int
> offset_add)
> > +                           uint8_t *data, int size, const char
> *format,
> > +                           int columns, int bytes, int offset_add)
> >  {
> >      AVBPrint bp;
> > -    int offset = 0, l, i;
> > +    unsigned offset = 0;
> > +    int l, i;
> > +
> > +    if (!name || !data || !format || columns <= 0 || bytes <= 0)
> > +        return;
> >
> >      av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
> >      av_bprintf(&bp, "\n");
> > @@ -607,12 +633,15 @@ int
> avtextwriter_context_open(AVTextWriterContext **pwctx, const
> AVTextWriter *w
> >      AVTextWriterContext *wctx;
> >      int ret = 0;
> >
> > -    if (!(wctx = av_mallocz(sizeof(AVTextWriterContext)))) {
> > +    if (!pwctx || !writer)
> > +        return AVERROR(EINVAL);
> > +
> > +    if (!((wctx = av_mallocz(sizeof(AVTextWriterContext))))) {
> >          ret = AVERROR(ENOMEM);
> >          goto fail;
> >      }
> >
> > -    if (!(wctx->priv = av_mallocz(writer->priv_size))) {
> > +    if (writer->priv_size && !((wctx->priv = av_mallocz(writer-
> >priv_size)))) {
> >          ret = AVERROR(ENOMEM);
> >          goto fail;
> >      }
> > diff --git a/fftools/textformat/avtextformat.h
> b/fftools/textformat/avtextformat.h
> > index c598af3450..aea691f351 100644
> > --- a/fftools/textformat/avtextformat.h
> > +++ b/fftools/textformat/avtextformat.h
> > @@ -21,9 +21,7 @@
> >  #ifndef FFTOOLS_TEXTFORMAT_AVTEXTFORMAT_H
> >  #define FFTOOLS_TEXTFORMAT_AVTEXTFORMAT_H
> >
> > -#include <stddef.h>
> >  #include <stdint.h>
> > -#include "libavutil/attributes.h"
> >  #include "libavutil/dict.h"
> >  #include "libavformat/avio.h"
> >  #include "libavutil/bprint.h"
> > @@ -103,7 +101,7 @@ struct AVTextFormatContext {
> >      unsigned int
> nb_item_type[SECTION_MAX_NB_LEVELS][SECTION_MAX_NB_SECTIONS];
> >
> >      /** section per each level */
> > -    const struct AVTextFormatSection
> *section[SECTION_MAX_NB_LEVELS];
> > +    const AVTextFormatSection *section[SECTION_MAX_NB_LEVELS];
> >      AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]; ///< generic
> print buffer dedicated to each section,
> >                                                    ///  used by
> various formatters
> >
> > @@ -124,7 +122,7 @@ struct AVTextFormatContext {
> >  #define AV_TEXTFORMAT_PRINT_STRING_VALIDATE 2
> >
> >  int avtext_context_open(AVTextFormatContext **ptctx, const
> AVTextFormatter *formatter, AVTextWriterContext *writer_context, const
> char *args,
> > -                        const struct AVTextFormatSection *sections,
> int nb_sections,
> > +                        const AVTextFormatSection *sections, int
> nb_sections,
> >                          int show_value_unit,
> >                          int use_value_prefix,
> >                          int use_byte_value_binary_prefix,
> > diff --git a/fftools/textformat/tf_default.c
> b/fftools/textformat/tf_default.c
> > index 2c5047eafd..ad97173b0b 100644
> > --- a/fftools/textformat/tf_default.c
> > +++ b/fftools/textformat/tf_default.c
> > @@ -68,9 +68,10 @@ DEFINE_FORMATTER_CLASS(default);
> >  /* lame uppercasing routine, assumes the string is lower case ASCII
> */
> >  static inline char *upcase_string(char *dst, size_t dst_size, const
> char *src)
> >  {
> > -    int i;
> > +    unsigned i;
> > +
> >      for (i = 0; src[i] && i < dst_size - 1; i++)
> > -        dst[i] = av_toupper(src[i]);
> > +        dst[i] = (char)av_toupper(src[i]);
> >      dst[i] = 0;
> >      return dst;
> >  }
> > @@ -106,6 +107,9 @@ static void
> default_print_section_footer(AVTextFormatContext *wctx)
> >      const struct AVTextFormatSection *section = wctx->section[wctx-
> >level];
> >      char buf[32];
> >
> > +    if (!section)
> > +        return;
> > +
> >      if (def->noprint_wrappers || def->nested_section[wctx->level])
> >          return;
> >
> > diff --git a/fftools/textformat/tf_ini.c
> b/fftools/textformat/tf_ini.c
> > index 88add0819a..dd77d0e8bf 100644
> > --- a/fftools/textformat/tf_ini.c
> > +++ b/fftools/textformat/tf_ini.c
> > @@ -91,7 +91,7 @@ static char *ini_escape_str(AVBPrint *dst, const
> char *src)
> >              /* fallthrough */
> >          default:
> >              if ((unsigned char)c < 32)
> > -                av_bprintf(dst, "\\x00%02x", c & 0xff);
> > +                av_bprintf(dst, "\\x00%02x", (unsigned char)c);
> >              else
> >                  av_bprint_chars(dst, c, 1);
> >              break;
> > diff --git a/fftools/textformat/tf_json.c
> b/fftools/textformat/tf_json.c
> > index b61d3740c6..e86cdbf5d9 100644
> > --- a/fftools/textformat/tf_json.c
> > +++ b/fftools/textformat/tf_json.c
> > @@ -80,13 +80,18 @@ static const char *json_escape_str(AVBPrint
> *dst, const char *src, void *log_ctx
> >      static const char json_subst[]  = { '"', '\\',  'b',  'f',
> 'n',  'r',  't', 0 };
> >      const char *p;
> >
> > +    if (!src) {
> > +        av_log(log_ctx, AV_LOG_ERROR, "json_escape_str: NULL source
> string\n");
> > +        return NULL;
> > +    }
> > +
> >      for (p = src; *p; p++) {
> >          char *s = strchr(json_escape, *p);
> >          if (s) {
> >              av_bprint_chars(dst, '\\', 1);
> >              av_bprint_chars(dst, json_subst[s - json_escape], 1);
> >          } else if ((unsigned char)*p < 32) {
> > -            av_bprintf(dst, "\\u00%02x", *p & 0xff);
> > +            av_bprintf(dst, "\\u00%02x", (unsigned char)*p);
> >          } else {
> >              av_bprint_chars(dst, *p, 1);
> >          }
> > @@ -105,6 +110,7 @@ static void
> json_print_section_header(AVTextFormatContext *wctx, const void *dat
> >          wctx->section[wctx->level-1] : NULL;
> >
> >      if (wctx->level && wctx->nb_item[wctx->level-1])
> > +    if (wctx->level && wctx->nb_item[wctx->level - 1])
> >          writer_put_str(wctx, ",\n");
> >
> >      if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER) {
> > diff --git a/fftools/textformat/tf_xml.c
> b/fftools/textformat/tf_xml.c
> > index befb39246d..28abfc6400 100644
> > --- a/fftools/textformat/tf_xml.c
> > +++ b/fftools/textformat/tf_xml.c
> > @@ -18,10 +18,7 @@
> >   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> 02110-1301 USA
> >   */
> >
> > -#include <limits.h>
> > -#include <stdarg.h>
> >  #include <stdint.h>
> > -#include <stdio.h>
> >  #include <string.h>
> >
> >  #include "avtextformat.h"
> > diff --git a/fftools/textformat/tw_avio.c
> b/fftools/textformat/tw_avio.c
> > index 6034f74ec9..b1743fb43a 100644
> > --- a/fftools/textformat/tw_avio.c
> > +++ b/fftools/textformat/tw_avio.c
> > @@ -53,7 +53,7 @@ static void io_w8(AVTextWriterContext *wctx, int
> b)
> >  static void io_put_str(AVTextWriterContext *wctx, const char *str)
> >  {
> >      IOWriterContext *ctx = wctx->priv;
> > -    avio_write(ctx->avio_context, str, strlen(str));
> > +    avio_write(ctx->avio_context, (const unsigned char *)str,
> (int)strlen(str));
> >  }
> >
> >  static void io_printf(AVTextWriterContext *wctx, const char *fmt,
> ...)
> > @@ -78,10 +78,12 @@ const AVTextWriter avtextwriter_avio = {
> >
> >  int avtextwriter_create_file(AVTextWriterContext **pwctx, const
> char *output_filename)
> >  {
> > +    if (!pwctx || !output_filename || !output_filename[0])
> > +        return AVERROR(EINVAL);
> 
> You said in [1] that you removed all these impossible checks, yet here
> they are; they are also above.
> 
> [1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2025-April/342317.html

The next commit removes it.


Thanks,
sw



_______________________________________________
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".