diff mbox series

[FFmpeg-devel,5/5] Fix printf specifiers for variables that will be switched to size_t

Message ID 20210317235958.1308987-5-andreas.rheinhardt@gmail.com
State Superseded
Headers show
Series [FFmpeg-devel,1/5] avcodec/avpacket: Improve overflow checks when packing dictionary
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt March 17, 2021, 11:59 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
There is btw an instance in ffprobe where a variable will have to be
switched to size_t when doing the bump. Hopefully it won't be forgotten.

 libavcodec/decode.c        |  5 +++++
 libavcodec/mpeg12enc.c     |  5 +++++
 libavcodec/mscc.c          |  5 +++++
 libavfilter/af_ashowinfo.c |  5 +++++
 libavfilter/vf_showinfo.c  | 15 +++++++++++++++
 libavformat/dump.c         |  5 +++++
 libavformat/framecrcenc.c  |  7 ++++++-
 libavformat/hashenc.c      |  9 +++++++--
 libavformat/matroskaenc.c  |  3 ++-
 libavformat/webvttdec.c    |  2 +-
 libavformat/webvttenc.c    | 18 ++++++++++++++----
 11 files changed, 70 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index efa8a9ac8d..74e0d0679e 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -2061,7 +2061,12 @@  int ff_copy_palette(void *dst, const AVPacket *src, void *logctx)
         memcpy(dst, pal, AVPALETTE_SIZE);
         return 1;
     } else if (pal) {
+#if FF_API_BUFFER_SIZE_T
         av_log(logctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size);
+#else
+        av_log(logctx, AV_LOG_ERROR,
+               "Palette size %"SIZE_SPECIFIER" is wrong\n", size);
+#endif
     }
     return 0;
 }
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index a05c2db6cb..1bc733aff0 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -574,8 +574,13 @@  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,
+#if FF_API_BUFFER_SIZE_T
                     "Warning Closed Caption size (%d) can not exceed 93 bytes "
                     "and must be a multiple of 3\n", side_data->size);
+#else
+                    "Closed Caption size (%"SIZE_SPECIFIER") can not exceed "
+                    "93 bytes and must be a multiple of 3\n", side_data->size);
+#endif
             }
         }
     }
diff --git a/libavcodec/mscc.c b/libavcodec/mscc.c
index fe02649623..4cec26f5b2 100644
--- a/libavcodec/mscc.c
+++ b/libavcodec/mscc.c
@@ -160,7 +160,12 @@  static int decode_frame(AVCodecContext *avctx,
             for (j = 0; j < 256; j++)
                 s->pal[j] = 0xFF000000 | AV_RL32(pal + j * 4);
         } else if (pal) {
+#if FF_API_BUFFER_SIZE_T
             av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size);
+#else
+            av_log(avctx, AV_LOG_ERROR,
+                   "Palette size %"SIZE_SPECIFIER" is wrong\n", size);
+#endif
         }
         memcpy(frame->data[1], s->pal, AVPALETTE_SIZE);
     }
diff --git a/libavfilter/af_ashowinfo.c b/libavfilter/af_ashowinfo.c
index 9046e8d84a..0e84bd8d65 100644
--- a/libavfilter/af_ashowinfo.c
+++ b/libavfilter/af_ashowinfo.c
@@ -170,7 +170,12 @@  static void dump_audio_service_type(AVFilterContext *ctx, AVFrameSideData *sd)
 
 static void dump_unknown(AVFilterContext *ctx, AVFrameSideData *sd)
 {
+#if FF_API_BUFFER_SIZE_T
     av_log(ctx, AV_LOG_INFO, "unknown side data type: %d, size %d bytes", sd->type, sd->size);
+#else
+    av_log(ctx, AV_LOG_INFO, "unknown side data type: %d, size "
+           "%"SIZE_SPECIFIER" bytes", sd->type, sd->size);
+#endif
 }
 
 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c
index 6208892005..bfcd5ebf72 100644
--- a/libavfilter/vf_showinfo.c
+++ b/libavfilter/vf_showinfo.c
@@ -314,7 +314,12 @@  static void dump_sei_unregistered_metadata(AVFilterContext *ctx, const AVFrameSi
     int i;
 
     if (sd->size < uuid_size) {
+#if FF_API_BUFFER_SIZE_T
         av_log(ctx, AV_LOG_ERROR, "invalid data(%d < UUID(%d-bytes))\n", sd->size, uuid_size);
+#else
+        av_log(ctx, AV_LOG_ERROR, "invalid data(%"SIZE_SPECIFIER" < "
+               "UUID(%d-bytes))\n", sd->size, uuid_size);
+#endif
         return;
     }
 
@@ -472,7 +477,12 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
             av_log(ctx, AV_LOG_INFO, "pan/scan");
             break;
         case AV_FRAME_DATA_A53_CC:
+#if FF_API_BUFFER_SIZE_T
             av_log(ctx, AV_LOG_INFO, "A/53 closed captions (%d bytes)", sd->size);
+#else
+            av_log(ctx, AV_LOG_INFO, "A/53 closed captions (%"SIZE_SPECIFIER" bytes)",
+                   sd->size);
+#endif
             break;
         case AV_FRAME_DATA_SPHERICAL:
             dump_spherical(ctx, frame, sd);
@@ -516,8 +526,13 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
             dump_sei_unregistered_metadata(ctx, sd);
             break;
         default:
+#if FF_API_BUFFER_SIZE_T
             av_log(ctx, AV_LOG_WARNING, "unknown side data type %d (%d bytes)\n",
                    sd->type, sd->size);
+#else
+            av_log(ctx, AV_LOG_WARNING, "unknown side data type %d "
+                   "(%"SIZE_SPECIFIER" bytes)\n", sd->type, sd->size);
+#endif
             break;
         }
 
diff --git a/libavformat/dump.c b/libavformat/dump.c
index 62ef5e9852..364cca9415 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -495,8 +495,13 @@  static void dump_sidedata(void *ctx, const AVStream *st, const char *indent)
             dump_s12m_timecode(ctx, st, sd);
             break;
         default:
+#if FF_API_BUFFER_SIZE_T
             av_log(ctx, AV_LOG_INFO,
                    "unknown side data type %d (%d bytes)", sd->type, sd->size);
+#else
+            av_log(ctx, AV_LOG_INFO, "unknown side data type %d "
+                   "(%"SIZE_SPECIFIER" bytes)", sd->type, sd->size);
+#endif
             break;
         }
 
diff --git a/libavformat/framecrcenc.c b/libavformat/framecrcenc.c
index 1fbe4aa4ee..dd7f3d227d 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,12 @@  static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
             default:
                 side_data_crc = av_adler32_update(0, data, sd->size);
             }
+#if FF_API_BUFFER_SIZE_T
             av_strlcatf(buf, sizeof(buf), ", %8d, 0x%08"PRIx32, pkt->side_data[i].size, side_data_crc);
+#else
+            av_strlcatf(buf, sizeof(buf), ", %8"SIZE_SPECIFIER", 0x%08"PRIx32,
+                        pkt->side_data[i].size, side_data_crc);
+#endif
         }
     }
     av_strlcatf(buf, sizeof(buf), "\n");
diff --git a/libavformat/hashenc.c b/libavformat/hashenc.c
index 1e9faf372a..1be3bfdd61 100644
--- a/libavformat/hashenc.c
+++ b/libavformat/hashenc.c
@@ -298,18 +298,23 @@  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);
+#if FF_API_BUFFER_SIZE_T
             snprintf(buf, sizeof(buf) - (AV_HASH_MAX_SIZE * 2 + 1), ", %8d, ", pkt->side_data[i].size);
+#else
+            snprintf(buf, sizeof(buf) - (AV_HASH_MAX_SIZE * 2 + 1),
+                     ", %8"SIZE_SPECIFIER", ", pkt->side_data[i].size);
+#endif
             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");