From patchwork Fri Nov 19 20:45:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 31511 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp2969162iob; Fri, 19 Nov 2021 12:46:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJzUcalV+HFnthpBN0YhXkSx37ZFreyLPdZoHSGKKnXA9xGM58lzIWr4rgD9HQAKZmFWFTrx X-Received: by 2002:a17:906:1be2:: with SMTP id t2mr11910769ejg.399.1637354768033; Fri, 19 Nov 2021 12:46:08 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b88si2401927edf.20.2021.11.19.12.46.07; Fri, 19 Nov 2021 12:46:08 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=lW+T+Xgo; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 91EEE68A785; Fri, 19 Nov 2021 22:46:03 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2046.outbound.protection.outlook.com [40.92.89.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 926A8680CB2 for ; Fri, 19 Nov 2021 22:45:56 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Op5WuYfOcFYDpwFdDwY+ifXnC9I1YmyIbTbMcf0hmSHvCmKtPNDk+rQNv+mSjcueqvLRTb17AJg3s2S+mowkA73mtHE2OjznN9Hohy084zn+Ng93qhs5Jm3F7rZxgwPu4GUvzdPqIdRzT8iSoiSBdr+bDj7UoGJKEC5gxEGlAzACjRWqMz39etqmEvQMztvfJysoQv+frl7JwaavzCSB6PLZbY5i1lbh30sIfSTMXSV2mhi66xpbkcHq/xGrtMkmsf/h7DKpIjbALBCq9IxCNT9mgFPpufeWY7Hq9kt188bfTA2sSj49OSu5MVQ/GDsjoF54LPKaystcJR7gakDDRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=5YaJHfWSRDsegz6OpNr/ndmBIOmuifa49LQPhWZBspI=; b=GwVxURczG4BaTJWrk5aP0GwatGxm4z4WCb8RGSDGD/Sw7LuEDzailbVDo7dUnHx+VfczC9s/R7Pc1xq84NwKYe6RBYtRiuZG/XwLZba1X1S9xB5pCFCa7Qdt39d4ait49PkTp1/yz8pVn6jxV7PFJhfxD96T5RNs8+u7ylnNtG5dmEB81yFSrVM3sXjDCdP+b7OhiXVEfVO9iXyquzAFTtM9erBxsSMEHeIAb7AFbExwlCDHm5vfuV6eij3AZR4XAaSnCM8jBTd4i7qZ5Y4F2BhgIc51CWYH/s6hzsFqZ5ekewrO2eYUqmPhdssrkSPnIszmTJlD5zENCXgsA9DJBA== 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=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5YaJHfWSRDsegz6OpNr/ndmBIOmuifa49LQPhWZBspI=; b=lW+T+Xgo0YjRJMUbFONqlrKGpe687weh0JNtUjvLR1wMvSUSGNpSAm9xIKN2cDMyAhGOmK8kDk3KZXvIZ0dNhvXXKN/AeUni6i7bkDY303Ux89VOSWPh2yy0EhIUJQnBWE9x4BubVFfuXY79k3AyD1oYII2hlWKdn/XibXjav2aZbNFju8a149yXvOdgLycXqquOu7pggBkC+PlyM04FkiFL5ixl/MXls6pcCbagbCo0mJVmXPVsNXL+qhBIHu/CaKaFjjPM1i1SpHQad4nB3Ig8LP6EuWncoRdzmDqcIQWU+iI6cppNO17FlmZ5JTQggCJbFfx3uJXRls3gDA6O+g== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (10.141.218.86) by AM6PR0302MB3191.eurprd03.prod.outlook.com (52.133.28.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.25; Fri, 19 Nov 2021 20:45:53 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::700f:d70b:3bb8:4d51]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::700f:d70b:3bb8:4d51%9]) with mapi id 15.20.4713.022; Fri, 19 Nov 2021 20:45:53 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 19 Nov 2021 21:45:45 +0100 Message-ID: X-Mailer: git-send-email 2.30.2 X-TMN: [wgXV8c3jsB4eiLj3CR+DP3HqnUyRvW0r] X-ClientProxiedBy: AM6P191CA0024.EURP191.PROD.OUTLOOK.COM (2603:10a6:209:8b::37) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211119204545.1121077-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.137.12) by AM6P191CA0024.EURP191.PROD.OUTLOOK.COM (2603:10a6:209:8b::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19 via Frontend Transport; Fri, 19 Nov 2021 20:45:53 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8bf61d82-29d2-4250-52c6-08d9ab9d9410 X-MS-Exchange-SLBlob-MailProps: f36zkjAOy3V7gDvsffph3HbG0V6eNcrrVvgHGpkRkFAImb2X22vGKuVe6YJ3drrnfF1WyAzLYjcwWR5LWY5nKX4BQ19Rc5+rI7rSLfc1PdC76kObOLy/BvPSFuhrd0GFPN0ksDvCva+8Q9IDRq/zV9G4nWF/jcmnLrP2+Ar5bqqXEuF+H8v6f6BhJBRfQC6Pt2qSk+sdSrZlmATmK8kBcck4joIlKmxD4lSBeAdc6c4uhPef5uL9JdXYZkzsLOKsoIcKa/gH5MRkXdB9LN8vE/zfTlayYwA9OKN8r4DvZ38OEb194TQDxJf9Vl5WcM+v1EccWER2sua+If7cYUjiUHqdT2ubE/UJ4UhQ07s/JaB4l3j7pXK66u47fPqpk4b3iADciIRYRHKuV49Tb7fEILg5Apelu2WHsDREBF9tDtqHgUHnE+WTDPLzidksNu6bnEucOASX2vPg1GyxLNixYGbVH621jXoY1TcVm0pV9Ipt6TW3ta7S9nBiIy8GYU4IC1Q5S4ghJBtfY6FTQMxP+CvaoA3dpxTGRYIBnABImyOzjyouMqayFfk3KYgQvbir1FWEQMvEvMp6ZqnxXdSijZkhh0TnPHUsTqM+3TkpyOtNHsUBjZbOnbJQWo4i7Po2VdyUwvXAT65XR2YFrYEQ8p7FRrhv1OdgST9lSmOVhJ9rkp98chqKR5nAaRMAMBAgXaBSQFy3a46+iqT0j9ox6manuuUtc/I/5XU6SfIiCdc= X-MS-TrafficTypeDiagnostic: AM6PR0302MB3191: X-Microsoft-Antispam: BCL:0;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x9CCKBdVt2v5eeMgAFkAw9P5PPoL0VK/IbAwAI29tLtfj5c3KEeVUoySSXEZAl0z11MyGTkVcvf7Or9rxFtuCeUVqen3Nguv0gKWP0/3yljTcQyPAEfIT9y9KODJhzw+RIQ1umYUOZcK8XVJFgR74PaUFA9N9xAHcCk9BZ0LgonuJPj5U+HqhdRaRXB9N/mF9mzjf5BOxiHiV0f+KEwwqBr+tIQpZ1mvhiosStaSrUqK7kvLJ3TVkicA0kTFjwbfNXTReeWPK4//e/Xiwrr8LFPsCN86510c56CyLR2vaGF3DutZe3gxoMImdbwGiD8QUmRzCDUifUHUs/iPvQ4gvQXzFSQg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8bf61d82-29d2-4250-52c6-08d9ab9d9410 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2021 20:45:53.4447 (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: AM6PR0302MB3191 Subject: [FFmpeg-devel] [PATCH] avcodec/smcenc: Avoid dangling pointers in context 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: JUy7en3EGnR5 Also reduces codesize: 24E6->2296B with GCC 10 and -O3. Signed-off-by: Andreas Rheinhardt --- libavcodec/smcenc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libavcodec/smcenc.c b/libavcodec/smcenc.c index 5b0035b244..52795efb5f 100644 --- a/libavcodec/smcenc.c +++ b/libavcodec/smcenc.c @@ -39,7 +39,6 @@ typedef struct SMCContext { AVFrame *prev_frame; // buffer for previous source frame - PutByteContext pb; uint8_t mono_value; int nb_distinct; @@ -110,9 +109,9 @@ static int count_distinct_items(const uint8_t *block_values, s->color_octets[i][6] == distinct_values[x] || \ s->color_octets[i][7] == distinct_values[x]) -static void smc_encode_stream(SMCContext *s, const AVFrame *frame) +static void smc_encode_stream(SMCContext *s, const AVFrame *frame, + PutByteContext *pb) { - PutByteContext *pb = &s->pb; const uint8_t *src_pixels = (const uint8_t *)frame->data[0]; const int stride = frame->linesize[0]; const uint8_t *prev_pixels = (const uint8_t *)s->prev_frame->data[0]; @@ -492,6 +491,7 @@ static int smc_encode_frame(AVCodecContext *avctx, AVPacket *pkt, { SMCContext *s = avctx->priv_data; const AVFrame *pict = frame; + PutByteContext pb; uint8_t *pal; int ret; @@ -506,18 +506,18 @@ static int smc_encode_frame(AVCodecContext *avctx, AVPacket *pkt, s->key_frame = 0; } - bytestream2_init_writer(&s->pb, pkt->data, pkt->size); + bytestream2_init_writer(&pb, pkt->data, pkt->size); - bytestream2_put_be32(&s->pb, 0x00); + bytestream2_put_be32(&pb, 0x00); pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE); if (!pal) return AVERROR(ENOMEM); memcpy(pal, frame->data[1], AVPALETTE_SIZE); - smc_encode_stream(s, pict); + smc_encode_stream(s, pict, &pb); - av_shrink_packet(pkt, bytestream2_tell_p(&s->pb)); + av_shrink_packet(pkt, bytestream2_tell_p(&pb)); pkt->data[0] = 0x0;