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 43D264D9D4 for <ffmpegdev@gitmailbox.com>; Mon, 21 Apr 2025 17:29:23 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 82DD4688001; Mon, 21 Apr 2025 20:29:20 +0300 (EEST) Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04olkn2055.outbound.protection.outlook.com [40.92.45.55]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9C49C687C82 for <ffmpeg-devel@ffmpeg.org>; Mon, 21 Apr 2025 20:29:18 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=v8KWljeg/C1ja5+IARodieiiydF7q9PMJiZ1gKHpKpF+b7XQUe8IHUpozzB5EWPbGU4TNOl+jA7HoMevS7s86epMYFoznOvfQN70LtBCqNdtiwvHvBUnwz7Nt7gSITAYiyRrX/HMslF1do/zST6vMF77Exr+vuiUVc1YJOYO6H+WDe08dEPaWRC/0QTCx7tUTunR/4UbPXQyteGvpsabuGOQk2i4eWGG0Zp9NBIPELXIpzyaALP2Iy1z9e+EiAI7ID/1MQ6iORyHUcLE8g+Eu6q4VnQ4+Pzyt2O/GkDywK7ktS1j5r69dgQ3Ej/EXM2pg6wWr7KHErXFoDBcB4CXUQ== 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=pS+3Jv96BxB+DRIdVPVtX9HxzmDzNT6L/QGwsgrSB1o=; b=W6HBB1at7niyZzY7R7XFbylX92l0fIFecxhskkqbdNfNSroyic7qXmDk6V/SewVHVYE8f9WJ5AQNEu+QKBUE+2/SfQBvIQc7pLPnLBQzeo2eIz37OqJEo6BJXNA24gDKCChq/9Sr5e8qxPSnOKFRagaktIyJah6CkvaGAJ1EO4kPn54XATOxgcmQsJu8Nmc4vR3f4pvMLcPGdAN5gRhvB9tN4AwHC89iHSBQd5Ke5LvNJ9cxdUVjRMWlQzrREKUN1qskJnOO0zxOUfjB9TtezPDfAJNBfFzRdNybLNZBd33bBUcjxHQlIyyxHYzIrrfs+wlYUx3U6Wv5M0osh2g1mw== 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=pS+3Jv96BxB+DRIdVPVtX9HxzmDzNT6L/QGwsgrSB1o=; b=m22LTVMKJlSZYT+VyinuUUEkAI2USx5Beyrla0bP9nAYUEksb2K+UHJEa0c6M3mPhLu5qn2qaeKOct067kTb32wQdXphcOgk73/cgPZv7UEHFiQ6r7mRDcBH+4TYoTaybO9SaZmHGRYClkHr9wTLjsnpO3NuSelFOZAwy6kX5lI1MFkUv2K/1N/JhUxgTYCOJtif88EokUbWgZVm5jGMazxTbGoG/hVaFepobKzeBiHkp6VY59RuDvniGqg00SaOUcc7jhh0TDMB6XuUwLA5Ed8Th4vPksvYvyz5jtM/2uBiP/ya7zNvh4g/Q4DxQ/UUh5MWRiqkZXH6UQJoldmewQ== Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM (2603:10b6:8:b::20) by SJ2P223MB1054.NAMP223.PROD.OUTLOOK.COM (2603:10b6:a03:593::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.35; Mon, 21 Apr 2025 17:29:15 +0000 Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::bf09:8e9:b07f:98a7]) by DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::bf09:8e9:b07f:98a7%4]) with mapi id 15.20.8655.033; Mon, 21 Apr 2025 17:29:15 +0000 From: "softworkz ." <softworkz-at-hotmail.com@ffmpeg.org> To: Stefano Sabatini <stefasab@gmail.com>, FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Thread-Topic: [FFmpeg-devel] [PATCH v4 02/11] fftools/textformat: Quality improvements Thread-Index: AQHbskfirCLvbbqOdkyJVJI5B+Lqm7OuXckAgAAAk8A= Date: Mon, 21 Apr 2025 17:29:14 +0000 Message-ID: <DM8P223MB036552FAAE05E57487D27D6ABAB82@DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM> References: <pull.66.v3.ffstaging.FFmpeg.1744945024.ffmpegagent@gmail.com> <pull.66.v4.ffstaging.FFmpeg.1745189954.ffmpegagent@gmail.com> <1516e67a5b216022a1ecc2292ee8e2989cfda192.1745189955.git.ffmpegagent@gmail.com> <aAZ9hFakRwILdeRP@mariano> In-Reply-To: <aAZ9hFakRwILdeRP@mariano> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM8P223MB0365:EE_|SJ2P223MB1054:EE_ x-ms-office365-filtering-correlation-id: fa59023d-95a4-4612-f694-08dd80fa09af x-microsoft-antispam: BCL:0; ARA:14566002|8062599003|8060799006|19110799003|461199028|7092599003|15080799006|10035399004|3412199025|4302099013|440099028|41001999003|102099032|1602099012; x-microsoft-antispam-message-info: =?us-ascii?Q?cGa0cm4AG/p4e3VPuo2+zD0WpBQchFOCnZ8BiIvA/9EGJXDKmEYb8H2wUMbJ?= =?us-ascii?Q?9hHB2oRCK+xeJsmri6LwQfiK7YLcKp/pbIMSBqu0fgOg5QWALs7FIBYnTJFH?= =?us-ascii?Q?MCvKDgSvvXK5VT9sdc7/0ApBO9xatxsEr7gkTKroYZpF5FsSdZvBtp5tezOP?= =?us-ascii?Q?9mVY7+7GqqlR62XvrNq3i3g8XVtQbyc83lVH/pBTdA7JX0TvuHt5JYwGTZ+K?= =?us-ascii?Q?Ahn/nfO3VVcRbcEjjVBha2o9TZY9sfTk+lvlTjhWda3YiMrp7ufudsUJcClN?= =?us-ascii?Q?tqMlapHz7YXsaW7d+2jdbLkToLGYAXXJdsY8xYi0qYLqeYhbcr7vRs4e23Ze?= =?us-ascii?Q?MzhaD9mxm7vQbAoBBHMWdE816W2RkEn7rmHx1aVN4Eu4tr4gpd56f4YmTBqj?= =?us-ascii?Q?3JXWTJPTBrR4d+ITBbwNU/iLvqJCp4rtL7ytimZY+4aQLUvzDil5Go/RK4kz?= =?us-ascii?Q?FvbjUt+xdSIelOjs+dc4BWOTcC1jrEDMRzeZ6Rr3OxTrOBWxF8Mn+xI+zunn?= =?us-ascii?Q?KmuWKz5mOloXh5cza1OqRxaJftaJs7CKGztVOuXe0mUvCe98rFdCrHromKNF?= =?us-ascii?Q?C4xsohCBxfSB4tUKl5b0x4MGIcQHl3Wld5KveV1ikavjPEmSTpyIlRyMRtTC?= =?us-ascii?Q?BEVop9M08ho/h03Qh6S+h9sS5Pwd6yqlfINpWw+89QVLIGsbH9vv2hCi+kgY?= =?us-ascii?Q?WRSmwo4wojBLAmgqV914ZJxs92KPM67Rb/zpNIQoe8GAdJfDpeq/kHAXe/r/?= =?us-ascii?Q?vxb+5v0olx27UXVDIzIogi5QjE2c9TNRJRhiURw67NuML2HnWCKlG10NinJC?= =?us-ascii?Q?TOO9AS4PhRjFojseOcRFhbjKzOZTsHTVNr5zjyxJOEs/0EVGcN7TSETNwE2S?= =?us-ascii?Q?QKxtFJfS8FsciKbKQ4OhzVa6a7uESLaZfP67FNgmJ5ZjGl93c9vD+D+tzacC?= =?us-ascii?Q?zSZ0s0TwG0zs0KfrnUHATwYx/NPejwvCOLsVndz2Hs/1U+t92hqzWGFSyKCF?= =?us-ascii?Q?hIwGx0w64lUM+p4Bx5InpKyzUC6Z1EEFmeM3tOFg3WyTNVdTblLrzA2vKI2H?= =?us-ascii?Q?WcwHyhGAMCsnMnguqa0Hf5SveyRblbiq5C3F9JQI70GX56xldYehZxkdIq0w?= =?us-ascii?Q?x1+gaBjxB7/P/P7TRkK+YlmzZnBKJLkZE/+PYyfynDrfVofP6ubB5cxirU3W?= =?us-ascii?Q?XBkLcn+iL0w0J6IwAl6zuuSBvrGi4IQ660xUUdf24iqt7ZEuhsHuudzwQiqV?= =?us-ascii?Q?M1pHJFc0xzwsiAq0Dos2p/wsE+R5IadT5Hy+4yW5WzubhuG1JC+6wPLQ0h2W?= =?us-ascii?Q?DdZwMViamS4suSXwgYE4gQ8/?= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?GL6I1R3Bwe769+ijqq+cq1u5u3n9j0HMXOM1NQHRvSiFJy3dEfiWaWU+bWDY?= =?us-ascii?Q?TmSPP9XnIe1KMnoVJb/hfMhJ6csYd3OyHcG/HUMGX+p8seUkwAla8OxLU/wH?= =?us-ascii?Q?gQ+mKat6REVrxlCfLu1AyGH1N0zHUjGqlC/CRHpmRqlLU8rSe0U1Xsxa4u5s?= =?us-ascii?Q?as+KiU/NBhO45AGT2QiG1hXub2MLyGQh8H0PSdp9avPx/RfF75e2oPbMRdaL?= =?us-ascii?Q?sv+PWoPwJUSh66JDgFJVDuEFVBe6SBIfgNx6jZbMCqBxLPYNfmyF4Dbo3pja?= =?us-ascii?Q?lcqPxpnf30G0d6FwWzLG2pvD6bgMBrV9h3/Yj73dOOwXacB29ujtkq//1d7e?= =?us-ascii?Q?fDSiQ7nOJvqUhok1Ko3PoSmI6j18mv0TcXglHcRsNlAPO1mhpBQNbEG4062i?= =?us-ascii?Q?QkHXT1xanyeOi/s+EuY9I4aQAx6+EJVyq5A0ZKREGjo1+gu9CPJ80+DHjdrV?= =?us-ascii?Q?8fQzfw8S88xcztQ/fwABlmZ3r8CPkCbOT1hoaJ8WQ+J8KdOh9/7UrvqgWwPq?= =?us-ascii?Q?cZpxvdmPmb375hCu6yR9BL0Nc39FY69jYayhtVimcm0hO7ZtpUWYmzbXMtwh?= =?us-ascii?Q?GFHaNtSZIdebPHyRjPIRV7EYSXV7T273oW1e+YQNAcJrNDi4pjuOkG6Q/PLO?= =?us-ascii?Q?9nfE2odt24KE3mE8i3PyVWnOG6mYMk/D3mn0bOigWiDdHNPo9hjyJH0FDsYk?= =?us-ascii?Q?Sb3PingzpEWTNy7wSGKfauWonL+rdJtl1IEku17EQMf5QhvD/HaPTRgddkQ1?= =?us-ascii?Q?0OvOVF/xhQjO6QAPffREWBcYbDtCFyU8QxuPIjYQ2kaGTukjG7U0H2ywsHb+?= =?us-ascii?Q?O8xr08dPGJUCCkCgJQqq7H3PTimnrbYAlHmZp3JmwYpMuxPVBMeCptUK+P94?= =?us-ascii?Q?DOLmYG8ofkaVEAFLi/CSZ9uZuDTll8NmxbR15Ux+dqSd9J0KSohW5iVki4zL?= =?us-ascii?Q?uXBKB62mMn43nEAQK9NqBwV0WsVqTYG+9OEhD4IHW4NpAX5RC91zOO6TKcQ1?= =?us-ascii?Q?BpGCc45DdxF72Ar/lVlvZtGOYTTQlA8b7oGQwpelDzBlLpDmKAl01zGxjiXD?= =?us-ascii?Q?2XcNB6jEEgpaEuE0pWzKfyaLWnvB0BTrBkrDHVmsg6OYJxbAtwpDrGAcGXeT?= =?us-ascii?Q?EKMTlnGjeKncle5kZ63lksbqthdJcTTsvHFmx8aIeSNB0RBwx2Uen2mTfSkN?= =?us-ascii?Q?vmrje84Fth/jGepd+3tTGEoqysLPMu9q9CPb4msLVyVezPdgH7F4Ozj5pf8?= =?us-ascii?Q?=3D?= MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-92255.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: fa59023d-95a4-4612-f694-08dd80fa09af X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Apr 2025 17:29:14.8789 (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: SJ2P223MB1054 Subject: Re: [FFmpeg-devel] [PATCH v4 02/11] 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/DM8P223MB036552FAAE05E57487D27D6ABAB82@DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM/> List-Archive: <https://master.gitmailbox.com/ffmpegdev/> List-Post: <mailto:ffmpegdev@gitmailbox.com> > -----Original Message----- > From: Stefano Sabatini <stefasab@gmail.com> > Sent: Montag, 21. April 2025 19:17 > To: FFmpeg development discussions and patches <ffmpeg- > devel@ffmpeg.org> > Cc: softworkz <softworkz@hotmail.com> > Subject: Re: [FFmpeg-devel] [PATCH v4 02/11] fftools/textformat: > Quality improvements > > On date Sunday 2025-04-20 22:59:05 +0000, softworkz wrote: > > From: softworkz <softworkz@hotmail.com> > > > > Nazigrammar commit log nit: use verb to specify the change action, > like in: apply quality improvements Sure. > > Also probably want to have some more details below the headline, > like: > > Perform multiple improvements to increase code robustness. > In particular: > * favor unsigned counters for loops > * add missing checks > * avoid possibly leaks > * move variable declarations to inner scopes when feasible > * provide explicit type-casting when needed Yea, that's better. Many thanks for writing it out! > > > 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 edbcd0b342..893b11298e 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))))) { > > Sorry to nitpick and if I miss the past discussion, why the added > parentheses? https://clang.llvm.org/extra/clang-tidy/checks/bugprone/assignment-in-if-condition.html > > 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); > > 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); > > + 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; > > possibly unrelated: maybe we should add an explicit warning or even an > assert? I agree, this is actually something that must not happen, not something that should be silently ignored. > > > + > > + 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; > > } > > Please split this to a dedicated commit, we want to have a > justification for this one in the commit log. Ok, will do. > > @@ -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]; > > ditto OK > > 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"); > > @@ -606,12 +632,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"); > > nit++: warning? > > About error semantic policy, from a quick grep it looks like FFmpeg > codebase avoids references to the function name, and only provides a > simple error description, we might do with: > > Cannot escape NULL string, returning NULL Alright. > > > + 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..d1b494b7b4 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 (!output_filename || !output_filename[0]) > > + return AVERROR(EINVAL); > > I'd add a warning to aid debugging. Right! > > IOWriterContext *ctx; > > int ret; > > > > - > > ret = avtextwriter_context_open(pwctx, &avtextwriter_avio); > > if (ret < 0) > > return ret; > > @@ -103,6 +105,9 @@ int avtextwriter_create_file(AVTextWriterContext > **pwctx, const char *output_fil > > > > int avtextwriter_create_avio(AVTextWriterContext **pwctx, > AVIOContext *avio_ctx, int close_on_uninit) > > { > > > + if (!pwctx || !avio_ctx) > > + return AVERROR(EINVAL); > > + > > maybe warning in this case as well Makes sense! > > [...] > > Looks good to me otherwise. Thank you! 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".