From patchwork Thu Mar 18 03:43:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26442 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 3010044B6F2 for ; Thu, 18 Mar 2021 05:43:29 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F198D6898E4; Thu, 18 Mar 2021 05:43:28 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B6E96688126 for ; Thu, 18 Mar 2021 05:43:22 +0200 (EET) Received: by mail-ed1-f46.google.com with SMTP id dm8so4873450edb.2 for ; Wed, 17 Mar 2021 20:43:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=ksHgH5NMjlk8gQ7d0J6NQcE6FTLIdvxKlSvWOs83dG8=; b=fp3txfdEqE6VyHURkvhTR0jWpH/meOQ2NEzAxQf9Y1ooQmQPu88F6NPdIdSlvTbKlO OKWTPB+IsdZWZZh7+zdt0McynC+WWTewegFJ3S26KEQZePoYlCDlR//tvzLqFGlNzpnQ 4u2uQwRQnJFmGEPn7JOEW5NiFb1nB/mXGrGCKWKuPTfNHJ/HsBqlfewlNbvx80JvXFwa oOpTxuMXPA4HNSCmFPGfkTmaVkbWCjtwEmzvwqeYwwxisaF7wq8Ex41+08gF+nQnWK0C 3tVDTtxoYen9ynLNkAKMzb3kVPIuajaTdrYvJKchZMsXv9lwJxjYj7r4TmBtrrWgF9As UtMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=ksHgH5NMjlk8gQ7d0J6NQcE6FTLIdvxKlSvWOs83dG8=; b=oHqzffFFeLESKb7F3fzexg3Ehplpwx4xn2dnXPPkKIXR9Yj6sZCrmLEzu/p74tGByA jy3C7vf4XAEUx6G9Y1OIfc4pLsC8PApyU5ol0TWjBuD0ST/gZytw0/55HjRAQu4EMFtp TZVkBS+q/8hwdFPZOprZ6aObNDoJ2fApYPB7QsY3nF/R7GcTsEJ9zFDLsuZwDFRzm84R bHpAeO6Ghi6qslUMW3iFEWtMPseC/Lp5bvHdEFOX3ajOj7P0RIY+MPlmYNLTXNm2vrex J128LxX7hIhCyFRfRMDysh/GblZ9eel93HbpLLQnDfpypm/TaVKXgPif9bN3Gz3idu9Q vmLg== X-Gm-Message-State: AOAM533R9p/GDHYJB9rNwKEKMHaqmKzSENlXsCkYxHDD9R3X/HiVGY47 bUroxfZT3EMNh1oQfHOx3Rw4DbS7AwGQZw== X-Google-Smtp-Source: ABdhPJyPSEyxTTZEzpPp+qWHPPLWtihIvg3umQS1AmTEehOfQuEdA5hXK7V/30wbX1iDdaMW103ujg== X-Received: by 2002:aa7:d7da:: with SMTP id e26mr1047130eds.269.1616039001828; Wed, 17 Mar 2021 20:43:21 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc08960.dynamic.kabel-deutschland.de. [188.192.137.96]) by smtp.gmail.com with ESMTPSA id g11sm708875edw.37.2021.03.17.20.43.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 20:43:21 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 18 Mar 2021 04:43:13 +0100 Message-Id: <20210318034314.1531570-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210317235958.1308987-1-andreas.rheinhardt@gmail.com> References: <20210317235958.1308987-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 5/6] Fix printf specifiers for variables that will be switched to size_t X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" Also fix some minor stuff like switching loop counters to size_t. Signed-off-by: Andreas Rheinhardt --- Now using a special define for the specifier instead of lots of #if. libavcodec/decode.c | 3 ++- libavcodec/mpeg12enc.c | 4 ++-- libavcodec/mscc.c | 3 ++- libavfilter/af_ashowinfo.c | 3 ++- libavfilter/vf_showinfo.c | 10 ++++++---- libavformat/dump.c | 4 ++-- libavformat/framecrcenc.c | 5 +++-- libavformat/hashenc.c | 7 ++++--- libavformat/matroskaenc.c | 3 ++- libavformat/webvttdec.c | 2 +- libavformat/webvttenc.c | 18 ++++++++++++++---- libavutil/internal.h | 2 ++ 12 files changed, 42 insertions(+), 22 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index efa8a9ac8d..c923b3e240 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -2061,7 +2061,8 @@ int ff_copy_palette(void *dst, const AVPacket *src, void *logctx) memcpy(dst, pal, AVPALETTE_SIZE); return 1; } else if (pal) { - av_log(logctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size); + av_log(logctx, AV_LOG_ERROR, + "Palette size %"BUFFER_SPECIFIER" is wrong\n", size); } return 0; } diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c index a05c2db6cb..771c9996a5 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -574,8 +574,8 @@ void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number) put_bits(&s->pb, 8, 0xff); // marker_bits } else { av_log(s->avctx, AV_LOG_WARNING, - "Warning Closed Caption size (%d) can not exceed 93 bytes " - "and must be a multiple of 3\n", side_data->size); + "Closed Caption size (%"BUFFER_SPECIFIER") can not exceed " + "93 bytes and must be a multiple of 3\n", side_data->size); } } } diff --git a/libavcodec/mscc.c b/libavcodec/mscc.c index fe02649623..08ae8cdbad 100644 --- a/libavcodec/mscc.c +++ b/libavcodec/mscc.c @@ -160,7 +160,8 @@ static int decode_frame(AVCodecContext *avctx, for (j = 0; j < 256; j++) s->pal[j] = 0xFF000000 | AV_RL32(pal + j * 4); } else if (pal) { - av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size); + av_log(avctx, AV_LOG_ERROR, + "Palette size %"BUFFER_SPECIFIER" is wrong\n", size); } memcpy(frame->data[1], s->pal, AVPALETTE_SIZE); } diff --git a/libavfilter/af_ashowinfo.c b/libavfilter/af_ashowinfo.c index 9046e8d84a..e7b1d92e3d 100644 --- a/libavfilter/af_ashowinfo.c +++ b/libavfilter/af_ashowinfo.c @@ -170,7 +170,8 @@ static void dump_audio_service_type(AVFilterContext *ctx, AVFrameSideData *sd) static void dump_unknown(AVFilterContext *ctx, AVFrameSideData *sd) { - av_log(ctx, AV_LOG_INFO, "unknown side data type: %d, size %d bytes", sd->type, sd->size); + av_log(ctx, AV_LOG_INFO, "unknown side data type: %d, size " + "%"BUFFER_SPECIFIER" bytes", sd->type, sd->size); } static int filter_frame(AVFilterLink *inlink, AVFrame *buf) diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c index 6208892005..21577dce7e 100644 --- a/libavfilter/vf_showinfo.c +++ b/libavfilter/vf_showinfo.c @@ -314,7 +314,8 @@ static void dump_sei_unregistered_metadata(AVFilterContext *ctx, const AVFrameSi int i; if (sd->size < uuid_size) { - av_log(ctx, AV_LOG_ERROR, "invalid data(%d < UUID(%d-bytes))\n", sd->size, uuid_size); + av_log(ctx, AV_LOG_ERROR, "invalid data(%"BUFFER_SPECIFIER" < " + "UUID(%d-bytes))\n", sd->size, uuid_size); return; } @@ -472,7 +473,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) av_log(ctx, AV_LOG_INFO, "pan/scan"); break; case AV_FRAME_DATA_A53_CC: - av_log(ctx, AV_LOG_INFO, "A/53 closed captions (%d bytes)", sd->size); + av_log(ctx, AV_LOG_INFO, "A/53 closed captions " + "(%"BUFFER_SPECIFIER" bytes)", sd->size); break; case AV_FRAME_DATA_SPHERICAL: dump_spherical(ctx, frame, sd); @@ -516,8 +518,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) dump_sei_unregistered_metadata(ctx, sd); break; default: - av_log(ctx, AV_LOG_WARNING, "unknown side data type %d (%d bytes)\n", - sd->type, sd->size); + av_log(ctx, AV_LOG_WARNING, "unknown side data type %d " + "(%"BUFFER_SPECIFIER" bytes)\n", sd->type, sd->size); break; } diff --git a/libavformat/dump.c b/libavformat/dump.c index 62ef5e9852..7b312f80a3 100644 --- a/libavformat/dump.c +++ b/libavformat/dump.c @@ -495,8 +495,8 @@ static void dump_sidedata(void *ctx, const AVStream *st, const char *indent) dump_s12m_timecode(ctx, st, sd); break; default: - av_log(ctx, AV_LOG_INFO, - "unknown side data type %d (%d bytes)", sd->type, sd->size); + av_log(ctx, AV_LOG_INFO, "unknown side data type %d " + "(%"BUFFER_SPECIFIER" bytes)", sd->type, sd->size); break; } diff --git a/libavformat/framecrcenc.c b/libavformat/framecrcenc.c index 1fbe4aa4ee..7cd77db84a 100644 --- a/libavformat/framecrcenc.c +++ b/libavformat/framecrcenc.c @@ -88,7 +88,7 @@ static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt) case AV_PKT_DATA_SPHERICAL: case AV_PKT_DATA_CONTENT_LIGHT_LEVEL: case AV_PKT_DATA_S12M_TIMECODE: - for (int j = 0; j < sd->size / 4; j++) { + for (size_t j = 0; j < sd->size / 4; j++) { uint8_t buf[4]; AV_WL32(buf, AV_RB32(sd->data + 4 * j)); side_data_crc = av_adler32_update(side_data_crc, buf, 4); @@ -119,7 +119,8 @@ static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt) default: side_data_crc = av_adler32_update(0, data, sd->size); } - av_strlcatf(buf, sizeof(buf), ", %8d, 0x%08"PRIx32, pkt->side_data[i].size, side_data_crc); + av_strlcatf(buf, sizeof(buf), ", %8"BUFFER_SPECIFIER", 0x%08"PRIx32, + pkt->side_data[i].size, side_data_crc); } } av_strlcatf(buf, sizeof(buf), "\n"); diff --git a/libavformat/hashenc.c b/libavformat/hashenc.c index 1e9faf372a..578b425195 100644 --- a/libavformat/hashenc.c +++ b/libavformat/hashenc.c @@ -298,18 +298,19 @@ static int framehash_write_packet(struct AVFormatContext *s, AVPacket *pkt) avio_write(s->pb, buf, strlen(buf)); if (c->format_version > 1 && pkt->side_data_elems) { - int i, j; + int i; avio_printf(s->pb, ", S=%d", pkt->side_data_elems); for (i = 0; i < pkt->side_data_elems; i++) { av_hash_init(c->hashes[0]); if (HAVE_BIGENDIAN && pkt->side_data[i].type == AV_PKT_DATA_PALETTE) { - for (j = 0; j < pkt->side_data[i].size; j += sizeof(uint32_t)) { + for (size_t j = 0; j < pkt->side_data[i].size; j += sizeof(uint32_t)) { uint32_t data = AV_RL32(pkt->side_data[i].data + j); av_hash_update(c->hashes[0], (uint8_t *)&data, sizeof(uint32_t)); } } else av_hash_update(c->hashes[0], pkt->side_data[i].data, pkt->side_data[i].size); - snprintf(buf, sizeof(buf) - (AV_HASH_MAX_SIZE * 2 + 1), ", %8d, ", pkt->side_data[i].size); + snprintf(buf, sizeof(buf) - (AV_HASH_MAX_SIZE * 2 + 1), + ", %8"BUFFER_SPECIFIER", ", pkt->side_data[i].size); len = strlen(buf); av_hash_final_hex(c->hashes[0], buf + len, sizeof(buf) - len); avio_write(s->pb, buf, strlen(buf)); diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 4931988efd..73cbfca90e 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2170,7 +2170,8 @@ static int mkv_write_vtt_blocks(AVFormatContext *s, AVIOContext *pb, const AVPac put_ebml_num(pb, track->track_num, track->track_num_size); avio_wb16(pb, ts - mkv->cluster_pts); avio_w8(pb, flags); - avio_printf(pb, "%.*s\n%.*s\n%.*s", id_size, id, settings_size, settings, pkt->size, pkt->data); + avio_printf(pb, "%.*s\n%.*s\n%.*s", (int)id_size, id, (int)settings_size, + settings, pkt->size, pkt->data); put_ebml_uint(pb, MATROSKA_ID_BLOCKDURATION, pkt->duration); end_ebml_master(pb, blockgroup); diff --git a/libavformat/webvttdec.c b/libavformat/webvttdec.c index 8d2fdfed37..cf060bd011 100644 --- a/libavformat/webvttdec.c +++ b/libavformat/webvttdec.c @@ -78,7 +78,7 @@ static int webvtt_read_header(AVFormatContext *s) int64_t pos; AVPacket *sub; const char *p, *identifier, *settings; - int identifier_len, settings_len; + size_t identifier_len, settings_len; int64_t ts_start, ts_end; ff_subtitles_read_chunk(s->pb, &cue); diff --git a/libavformat/webvttenc.c b/libavformat/webvttenc.c index 552bc38b65..342cba6dd8 100644 --- a/libavformat/webvttenc.c +++ b/libavformat/webvttenc.c @@ -72,8 +72,13 @@ static int webvtt_write_packet(AVFormatContext *ctx, AVPacket *pkt) id = av_packet_get_side_data(pkt, AV_PKT_DATA_WEBVTT_IDENTIFIER, &id_size); - if (id && id_size > 0) - avio_printf(pb, "%.*s\n", id_size, id); + if (id && id_size > 0) { +#if !FF_API_BUFFER_SIZE_T + if (id_size > INT_MAX) + return AVERROR(ERANGE); +#endif + avio_printf(pb, "%.*s\n", (int)id_size, id); + } webvtt_write_time(pb, pkt->pts); avio_printf(pb, " --> "); @@ -82,8 +87,13 @@ static int webvtt_write_packet(AVFormatContext *ctx, AVPacket *pkt) settings = av_packet_get_side_data(pkt, AV_PKT_DATA_WEBVTT_SETTINGS, &settings_size); - if (settings && settings_size > 0) - avio_printf(pb, " %.*s", settings_size, settings); + if (settings && settings_size > 0) { +#if !FF_API_BUFFER_SIZE_T + if (id_size > INT_MAX) + return AVERROR(ERANGE); +#endif + avio_printf(pb, " %.*s", (int)settings_size, settings); + } avio_printf(pb, "\n"); diff --git a/libavutil/internal.h b/libavutil/internal.h index 572daefec3..989efeab5c 100644 --- a/libavutil/internal.h +++ b/libavutil/internal.h @@ -302,8 +302,10 @@ int avpriv_dict_set_timestamp(AVDictionary **dict, const char *key, int64_t time // Temporary typedef to simplify porting all AVBufferRef users to size_t #if FF_API_BUFFER_SIZE_T typedef int buffer_size_t; +#define BUFFER_SPECIFIER "d" #else typedef size_t buffer_size_t; +#define BUFFER_SPECIFIER SIZE_SPECIFIER #endif #endif /* AVUTIL_INTERNAL_H */