[FFmpeg-devel] [PATCH] Remove printf format string errors in windows builds

Larry Robinson silver-dad
Sun Jan 23 23:58:23 CET 2011


Both Mingw32 and Mingw64 rely on msvcrt.dll to interpret format strings
for printf, sscanf, etc. and so gcc doesn't recognize `t' or `z' width
specifications for 64-bit types on windows. It therefore produces warnings
and incorrect code for format strings containing `%td', `%zd', ...

This patch uses #ifndef _WIN32 to replace these specifiers with `%Id'
(the windows equivalent) for windows builds.

Cheers!
Larry Robinson

---
  libavcodec/4xm.c             |    4 ++++
  libavcodec/dvdsubenc.c       |    4 ++++
  libavcodec/h264.c            |    4 ++++
  libavcodec/interplayvideo.c  |    4 ++++
  libavcodec/mjpegdec.c        |   12 ++++++++++++
  libavcodec/mpeg12.c          |    4 ++++
  libavcodec/wmavoice.c        |    4 ++++
  libavcodec/zmbv.c            |   12 ++++++++++++
  libavformat/mmsh.c           |    8 ++++++++
  libavformat/mmst.c           |    8 ++++++++
  libavformat/oggparsevorbis.c |    4 ++++
  libavformat/rtpdec_xiph.c    |    8 ++++++++
  libavformat/sdp.c            |    4 ++++
  13 files changed, 80 insertions(+), 0 deletions(-)

diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c
index 30c4c59..daeda1b 100644
--- a/libavcodec/4xm.c
+++ b/libavcodec/4xm.c
@@ -417,7 +417,11 @@ static int decode_p_frame(FourXContext *f, const 
uint8_t *buf, int length){
      if(   bitstream_size != (get_bits_count(&f->gb)+31)/32*4
         || (((const char*)f->wordstream - (const char*)buf + 2)&~2) != 
extra + bitstream_size + wordstream_size
         || (((const char*)f->bytestream - (const char*)buf + 3)&~3) != 
extra + bitstream_size + wordstream_size + bytestream_size)
+#ifndef _WIN32
          av_log(f->avctx, AV_LOG_ERROR, " %d %td %td bytes left\n",
+#else
+        av_log(f->avctx, AV_LOG_ERROR, " %d %Id %Id bytes left\n",
+#endif
              bitstream_size - (get_bits_count(&f->gb)+31)/32*4,
              -(((const char*)f->bytestream - (const char*)buf + 3)&~3) 
+ (extra + bitstream_size + wordstream_size + bytestream_size),
              -(((const char*)f->wordstream - (const char*)buf + 2)&~2) 
+ (extra + bitstream_size + wordstream_size)
diff --git a/libavcodec/dvdsubenc.c b/libavcodec/dvdsubenc.c
index 4ee0f37..f079963 100644
--- a/libavcodec/dvdsubenc.c
+++ b/libavcodec/dvdsubenc.c
@@ -200,7 +200,11 @@ static int encode_dvd_subtitles(uint8_t *outbuf, 
int outbuf_size,
      qq = outbuf;
      bytestream_put_be16(&qq, q - outbuf);

+#ifndef _WIN32
      av_log(NULL, AV_LOG_DEBUG, "subtitle_packet size=%td\n", q - outbuf);
+#else
+    av_log(NULL, AV_LOG_DEBUG, "subtitle_packet size=%Id\n", q - outbuf);
+#endif
      return q - outbuf;
  }

diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index d56c293..138ffda 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -2536,7 +2536,11 @@ static int decode_slice(struct AVCodecContext 
*avctx, void *arg){
                  return 0;
              }
              if( ret < 0 || h->cabac.bytestream > 
h->cabac.bytestream_end + 2) {
+#ifndef _WIN32
                  av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding 
MB %d %d, bytestream (%td)\n", s->mb_x, s->mb_y, h->cabac.bytestream_end 
- h->cabac.bytestream);
+#else
+                av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding 
MB %d %d, bytestream (%Id)\n", s->mb_x, s->mb_y, h->cabac.bytestream_end 
- h->cabac.bytestream);
+#endif
                  ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, 
s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
                  return -1;
              }
diff --git a/libavcodec/interplayvideo.c b/libavcodec/interplayvideo.c
index 34f0557..ec94c21 100644
--- a/libavcodec/interplayvideo.c
+++ b/libavcodec/interplayvideo.c
@@ -1010,7 +1010,11 @@ static void ipvideo_decode_opcodes(IpvideoContext *s)
          }
      }
      if (s->stream_end - s->stream_ptr > 1) {
+#ifndef _WIN32
          av_log(s->avctx, AV_LOG_ERROR, " Interplay video: decode 
finished with %td bytes left over\n",
+#else
+        av_log(s->avctx, AV_LOG_ERROR, " Interplay video: decode 
finished with %Id bytes left over\n",
+#endif
                 s->stream_end - s->stream_ptr);
      }
  }
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 19bd2f7..9e1b059 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -1282,7 +1282,11 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx,
              if (start_code < 0) {
                  goto the_end;
              } else {
+#ifndef _WIN32
                  av_log(avctx, AV_LOG_DEBUG, "marker=%x 
avail_size_in_buf=%td\n", start_code, buf_end - buf_ptr);
+#else
+                av_log(avctx, AV_LOG_DEBUG, "marker=%x 
avail_size_in_buf=%Id\n", start_code, buf_end - buf_ptr);
+#endif

                  if ((buf_end - buf_ptr) > s->buffer_size)
                  {
@@ -1319,7 +1323,11 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx,
                      }
                      init_get_bits(&s->gb, s->buffer, (dst - s->buffer)*8);

+#ifndef _WIN32
                      av_log(avctx, AV_LOG_DEBUG, "escaping removed %td 
bytes\n",
+#else
+                    av_log(avctx, AV_LOG_DEBUG, "escaping removed %Id 
bytes\n",
+#endif
                             (buf_end - buf_ptr) - (dst - s->buffer));
                  }
                  else if(start_code == SOS && s->ls){
@@ -1507,7 +1515,11 @@ not_the_end:
      av_log(avctx, AV_LOG_FATAL, "No JPEG data found in image\n");
      return -1;
  the_end:
+#ifndef _WIN32
      av_log(avctx, AV_LOG_DEBUG, "mjpeg decode frame unused %td 
bytes\n", buf_end - buf_ptr);
+#else
+    av_log(avctx, AV_LOG_DEBUG, "mjpeg decode frame unused %Id 
bytes\n", buf_end - buf_ptr);
+#endif
  //    return buf_end - buf_ptr;
      return buf_ptr - buf;
  }
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index d93474f..fb4ff54 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -2315,7 +2315,11 @@ static int decode_chunks(AVCodecContext *avctx,
          input_size = buf_end - buf_ptr;

          if(avctx->debug & FF_DEBUG_STARTCODE){
+#ifndef _WIN32
              av_log(avctx, AV_LOG_DEBUG, "%3X at %td left %d\n", 
start_code, buf_ptr-buf, input_size);
+#else
+            av_log(avctx, AV_LOG_DEBUG, "%3X at %Id left %d\n", 
start_code, buf_ptr-buf, input_size);
+#endif
          }

          /* prepare data for next start code */
diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c
index aa3b2b8..2700e53 100644
--- a/libavcodec/wmavoice.c
+++ b/libavcodec/wmavoice.c
@@ -1904,7 +1904,11 @@ static int wmavoice_decode_packet(AVCodecContext 
*ctx, void *data,

      if (*data_size < 480 * sizeof(float)) {
          av_log(ctx, AV_LOG_ERROR,
+#ifndef _WIN32
                 "Output buffer too small (%d given - %zu needed)\n",
+#else
+               "Output buffer too small (%d given - %Iu needed)\n",
+#endif
                 *data_size, 480 * sizeof(float));
          return -1;
      }
diff --git a/libavcodec/zmbv.c b/libavcodec/zmbv.c
index 6ac9089..e0bc2ce 100644
--- a/libavcodec/zmbv.c
+++ b/libavcodec/zmbv.c
@@ -142,7 +142,11 @@ static int zmbv_decode_xor_8(ZmbvContext *c)
          prev += c->width * c->bh;
      }
      if(src - c->decomp_buf != c->decomp_len)
+#ifndef _WIN32
          av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n", 
src-c->decomp_buf, c->decomp_len);
+#else
+        av_log(c->avctx, AV_LOG_ERROR, "Used %Ii of %i bytes\n", 
src-c->decomp_buf, c->decomp_len);
+#endif
      return 0;
  }

@@ -215,7 +219,11 @@ static int zmbv_decode_xor_16(ZmbvContext *c)
          prev += c->width * c->bh;
      }
      if(src - c->decomp_buf != c->decomp_len)
+#ifndef _WIN32
          av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n", 
src-c->decomp_buf, c->decomp_len);
+#else
+        av_log(c->avctx, AV_LOG_ERROR, "Used %Ii of %i bytes\n", 
src-c->decomp_buf, c->decomp_len);
+#endif
      return 0;
  }

@@ -371,7 +379,11 @@ static int zmbv_decode_xor_32(ZmbvContext *c)
          prev += c->width * c->bh;
      }
      if(src - c->decomp_buf != c->decomp_len)
+#ifndef _WIN32
          av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n", 
src-c->decomp_buf, c->decomp_len);
+#else
+        av_log(c->avctx, AV_LOG_ERROR, "Used %Ii of %i bytes\n", 
src-c->decomp_buf, c->decomp_len);
+#endif
      return 0;
  }

diff --git a/libavformat/mmsh.c b/libavformat/mmsh.c
index 3581431..7a23e5c 100644
--- a/libavformat/mmsh.c
+++ b/libavformat/mmsh.c
@@ -117,7 +117,11 @@ static int read_data_packet(MMSHContext *mmsh, 
const int len)
      int res;
      if (len > sizeof(mms->in_buffer)) {
          av_log(NULL, AV_LOG_ERROR,
+#ifndef _WIN32
                 "Data packet length %d exceeds the in_buffer size %zu\n",
+#else
+               "Data packet length %d exceeds the in_buffer size %Iu\n",
+#endif
                 len, sizeof(mms->in_buffer));
          return AVERROR(EIO);
      }
@@ -192,7 +196,11 @@ static int get_http_header_data(MMSHContext *mmsh)
              if (len) {
                  if (len > sizeof(mms->in_buffer)) {
                      av_log(NULL, AV_LOG_ERROR,
+#ifndef _WIN32
                             "Other packet len = %d exceed the in_buffer 
size %zu\n",
+#else
+                           "Other packet len = %d exceed the in_buffer 
size %Iu\n",
+#endif
                             len, sizeof(mms->in_buffer));
                      return AVERROR(EIO);
                  }
diff --git a/libavformat/mmst.c b/libavformat/mmst.c
index 08e3b3e..e4ca53f 100644
--- a/libavformat/mmst.c
+++ b/libavformat/mmst.c
@@ -275,7 +275,11 @@ static MMSSCPacketType 
get_tcp_server_response(MMSTContext *mmst)
              if (length_remaining < 0
                  || length_remaining > sizeof(mms->in_buffer) - 12) {
                  av_log(NULL, AV_LOG_ERROR,
+#ifndef _WIN32
                         "Incoming packet length %d exceeds bufsize %zu\n",
+#else
+                       "Incoming packet length %d exceeds bufsize %Iu\n",
+#endif
                         length_remaining, sizeof(mms->in_buffer) - 12);
                  return AVERROR_INVALIDDATA;
              }
@@ -312,7 +316,11 @@ static MMSSCPacketType 
get_tcp_server_response(MMSTContext *mmst)
              if (length_remaining < 0
                  || length_remaining > sizeof(mms->in_buffer) - 8) {
                  av_log(NULL, AV_LOG_ERROR,
+#ifndef _WIN32
                         "Data length %d is invalid or too large 
(max=%zu)\n",
+#else
+                       "Data length %d is invalid or too large 
(max=%Iu)\n",
+#endif
                         length_remaining, sizeof(mms->in_buffer));
                  return AVERROR_INVALIDDATA;
              }
diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
index cdb0266..86df2c5 100644
--- a/libavformat/oggparsevorbis.c
+++ b/libavformat/oggparsevorbis.c
@@ -133,7 +133,11 @@ ff_vorbis_comment(AVFormatContext * as, AVMetadata 
**m, const uint8_t *buf, int
      }

      if (p != end)
+#ifndef _WIN32
          av_log(as, AV_LOG_INFO, "%ti bytes of comment header 
remain\n", end-p);
+#else
+        av_log(as, AV_LOG_INFO, "%Ii bytes of comment header remain\n", 
end-p);
+#endif
      if (n > 0)
          av_log(as, AV_LOG_INFO,
                 "truncated comment header, %i comments not found\n", n);
diff --git a/libavformat/rtpdec_xiph.c b/libavformat/rtpdec_xiph.c
index fe17a42..3d73598 100644
--- a/libavformat/rtpdec_xiph.c
+++ b/libavformat/rtpdec_xiph.c
@@ -254,7 +254,11 @@ parse_packed_headers(const uint8_t * packed_headers,

      if (packed_headers_end - packed_headers < 9) {
          av_log(codec, AV_LOG_ERROR,
+#ifndef _WIN32
                 "Invalid %td byte packed header.",
+#else
+               "Invalid %Id byte packed header.",
+#endif
                 packed_headers_end - packed_headers);
          return AVERROR_INVALIDDATA;
      }
@@ -276,7 +280,11 @@ parse_packed_headers(const uint8_t * packed_headers,
      if (packed_headers_end - packed_headers != length ||
          length1 > length || length2 > length - length1) {
          av_log(codec, AV_LOG_ERROR,
+#ifndef _WIN32
                 "Bad packed header lengths (%d,%d,%td,%d)\n", length1,
+#else
+               "Bad packed header lengths (%d,%d,%Id,%d)\n", length1,
+#endif
                 length2, packed_headers_end - packed_headers, length);
          return AVERROR_INVALIDDATA;
      }
diff --git a/libavformat/sdp.c b/libavformat/sdp.c
index 872e76c..e8ecf02 100644
--- a/libavformat/sdp.c
+++ b/libavformat/sdp.c
@@ -196,7 +196,11 @@ static char *extradata2psets(AVCodecContext *c)
              p++;
          }
          if (av_base64_encode(p, MAX_PSET_SIZE - (p - psets), r, r1 - 
r) == NULL) {
+#ifndef _WIN32
              av_log(c, AV_LOG_ERROR, "Cannot Base64-encode %td %td!\n", 
MAX_PSET_SIZE - (p - psets), r1 - r);
+#else
+            av_log(c, AV_LOG_ERROR, "Cannot Base64-encode %Id %Id!\n", 
MAX_PSET_SIZE - (p - psets), r1 - r);
+#endif
              av_free(psets);

              return NULL;
-- 
1.7.2.3.msysgit.0




More information about the ffmpeg-devel mailing list