[FFmpeg-devel] [PATCH] Fix MSVC warnings about possible value truncation.

wm4 nfxjfg at googlemail.com
Wed Sep 3 00:19:28 CEST 2014


On Fri, 29 Aug 2014 15:44:34 -0700
Peter Kasting <pkasting at google.com> wrote:

> From 1c94e78d2b2037d492ea5abb3edb7960c8e98a1d Mon Sep 17 00:00:00 2001
> From: Peter Kasting <pkasting at google.com>
> Date: Fri, 29 Aug 2014 15:31:41 -0700
> Subject: [PATCH] Fix MSVC warnings about possible value truncation.

Tried to review it. Here's why patches like these are bad: they're
HUGE. Reviewing them takes a lot of time, and the result is
questionable. How are we going to do v2 of this patch? And v3 etc.?
Probably not at all. It's just too monolithic. It's like reviewing a
phone book.

Another problem: this mixes hiding compiler warnings and trying to fix
real problems. And in many cases, hiding real problems. Just plastering
everything with "(type)expr" won't help much, especially not if "type"
is signed, because it doesn't change anything about the legality of an
overflow.

For the next time, I'd suggest putting every real fix (or attempt of a
fix) into a separate patch - even if it results in dozens of patches.
At least this makes it easier to see what patch got rejected, what got
accepted, and what needs further work.

In general, this reinforces my belief that enabling compiler warnings
with large potential for false positives, and then hiding the warnings
by making the compiler happy (without really fixing the issue), is a
very bad idea.

> ---
>  compat/strtod.c                |  2 +-
>  libavcodec/avpacket.c          |  4 +-
>  libavcodec/bitstream.c         | 14 +++----
>  libavcodec/fft-internal.h      |  6 +--
>  libavcodec/opus.c              |  2 +-
>  libavcodec/rdft.c              |  6 +--
>  libavcodec/utils.c             | 21 +++++-----
>  libavcodec/vorbisdec.c         | 19 ++++-----
>  libavcodec/vp3.c               |  7 ++--
>  libavformat/aviobuf.c          |  4 +-
>  libavformat/cutils.c           |  6 +--
>  libavformat/internal.h         |  1 +
>  libavformat/isom.c             |  2 +-
>  libavformat/matroskadec.c      | 87 +++++++++++++++++++++---------------------
>  libavformat/mux.c              | 10 ++---
>  libavformat/oggparseogm.c      |  6 +--
>  libavformat/oggparseopus.c     |  8 ++--
>  libavformat/oggparsespeex.c    |  4 +-
>  libavformat/oggparsevorbis.c   |  6 ++-
>  libavformat/pcm.c              |  2 +-
>  libavformat/riffdec.c          |  2 +-
>  libavformat/utils.c            | 28 +++++++-------
>  libavformat/wavdec.c           | 16 ++++----
>  libavutil/avstring.c           |  2 +-
>  libavutil/bswap.h              |  2 +-
>  libavutil/eval.c               | 16 ++++----
>  libavutil/intfloat_readwrite.c | 13 ++++---
>  libavutil/opt.c                | 38 +++++++++---------
>  libavutil/parseutils.c         |  6 +--
>  libavutil/rational.c           | 10 ++---
>  libavutil/utils.c              |  2 +-
>  31 files changed, 180 insertions(+), 172 deletions(-)
> 
> diff --git a/compat/strtod.c b/compat/strtod.c
> index 3a9452e..51d30bf 100644
> --- a/compat/strtod.c
> +++ b/compat/strtod.c
> @@ -81,7 +81,7 @@ double avpriv_strtod(const char *nptr, char **endptr)
>                 !av_strncasecmp(nptr, "+0x", 3)) {
>          /* FIXME this doesn't handle exponents, non-integers (float/double)
>           * and numbers too large for long long */
> -        res = strtoll(nptr, &end, 16);
> +        res = (double)strtoll(nptr, &end, 16);

Pointless cast.

>      } else {
>          res = strtod(nptr, &end);
>      }
> diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> index a87e8e3..739231c 100644
> --- a/libavcodec/avpacket.c
> +++ b/libavcodec/avpacket.c
> @@ -351,7 +351,7 @@ int av_packet_merge_side_data(AVPacket *pkt){
>          }
>          if (size > INT_MAX)
>              return AVERROR(EINVAL);
> -        buf = av_buffer_alloc(size);
> +        buf = av_buffer_alloc((int)size);

False positive; size is explicitly checked above.

>          if (!buf)
>              return AVERROR(ENOMEM);
>          pkt->buf = buf;
> @@ -361,7 +361,7 @@ FF_DISABLE_DEPRECATION_WARNINGS
>          pkt->destruct = dummy_destruct_packet;
>  FF_ENABLE_DEPRECATION_WARNINGS
>  #endif
> -        pkt->size = size - FF_INPUT_BUFFER_PADDING_SIZE;
> +        pkt->size = (int)size - FF_INPUT_BUFFER_PADDING_SIZE;

Same as above.

>          bytestream_put_buffer(&p, old.data, old.size);
>          for (i=old.side_data_elems-1; i>=0; i--) {
>              bytestream_put_buffer(&p, old.side_data[i].data, old.side_data[i].size);
> diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c
> index d041643..1665c68 100644
> --- a/libavcodec/bitstream.c
> +++ b/libavcodec/bitstream.c
> @@ -85,18 +85,18 @@ void avpriv_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
>  
>  /* VLC decoding */
>  
> -#define GET_DATA(v, table, i, wrap, size)                   \
> +#define GET_DATA(type, v, table, i, wrap, size)             \
>  {                                                           \
>      const uint8_t *ptr = (const uint8_t *)table + i * wrap; \
>      switch(size) {                                          \
>      case 1:                                                 \
> -        v = *(const uint8_t *)ptr;                          \
> +        v = (type)*(const uint8_t *)ptr;                    \
>          break;                                              \
>      case 2:                                                 \
> -        v = *(const uint16_t *)ptr;                         \
> +        v = (type)*(const uint16_t *)ptr;                   \
>          break;                                              \
>      default:                                                \
> -        v = *(const uint32_t *)ptr;                         \
> +        v = (type)*(const uint32_t *)ptr;                   \
>          break;                                              \
>      }                                                       \
>  }
> @@ -302,7 +302,7 @@ int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes,
>      j = 0;
>  #define COPY(condition)\
>      for (i = 0; i < nb_codes; i++) {                                        \
> -        GET_DATA(buf[j].bits, bits, i, bits_wrap, bits_size);               \
> +        GET_DATA(uint8_t, buf[j].bits, bits, i, bits_wrap, bits_size);      \
>          if (!(condition))                                                   \
>              continue;                                                       \
>          if (buf[j].bits > 3*nb_bits || buf[j].bits>32) {                    \
> @@ -311,7 +311,7 @@ int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes,
>                  av_free(buf);                                               \
>              return -1;                                                      \
>          }                                                                   \
> -        GET_DATA(buf[j].code, codes, i, codes_wrap, codes_size);            \
> +        GET_DATA(uint32_t, buf[j].code, codes, i, codes_wrap, codes_size);  \
>          if (buf[j].code >= (1LL<<buf[j].bits)) {                            \
>              av_log(NULL, AV_LOG_ERROR, "Invalid code in init_vlc\n");       \
>              if (!(flags & INIT_VLC_USE_NEW_STATIC))                         \
> @@ -323,7 +323,7 @@ int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes,
>          else                                                                \
>              buf[j].code <<= 32 - buf[j].bits;                               \
>          if (symbols)                                                        \
> -            GET_DATA(buf[j].symbol, symbols, i, symbols_wrap, symbols_size) \
> +            GET_DATA(uint16_t, buf[j].symbol, symbols, i, symbols_wrap, symbols_size)\
>          else                                                                \
>              buf[j].symbol = i;                                              \
>          j++;                                                                \

Can't tell, but should be technically fine since the target is
unsigned. So there's no undefined behavior, and possible bugs seem
unlikely since the code obviously works.

> diff --git a/libavcodec/fft-internal.h b/libavcodec/fft-internal.h
> index 0a8f7d0..648c023 100644
> --- a/libavcodec/fft-internal.h
> +++ b/libavcodec/fft-internal.h
> @@ -21,7 +21,7 @@
>  
>  #if FFT_FLOAT
>  
> -#define FIX15(v) (v)
> +#define FIX15(v) (FFTSample)(v)
>  #define sqrthalf (float)M_SQRT1_2
>  
>  #define BF(x, y, a, b) do {                     \
> @@ -50,7 +50,7 @@
>          (dim)   = (int)(((accu) + 0x40000000) >> 31);       \
>      } while (0)
>  
> -#define FIX15(a) av_clip(SCALE_FLOAT(a, 31), -2147483647, 2147483647)
> +#define FIX15(a) (FFTSample)av_clip(SCALE_FLOAT(a, 31), -2147483647, 2147483647)
>  
>  #else /* FFT_FIXED_32 */
>  
> @@ -59,7 +59,7 @@
>  
>  void ff_mdct_calcw_c(FFTContext *s, FFTDouble *output, const FFTSample *input);
>  
> -#define FIX15(a) av_clip(SCALE_FLOAT(a, 15), -32767, 32767)
> +#define FIX15(a) (FFTSample)av_clip(SCALE_FLOAT(a, 15), -32767, 32767)
>  
>  #define sqrthalf ((int16_t)((1<<15)*M_SQRT1_2))
>  

In both hunks, the warnings are false positives, because av_clip clips
the value range to the target type range.

> diff --git a/libavcodec/opus.c b/libavcodec/opus.c
> index e76c510..0520410 100644
> --- a/libavcodec/opus.c
> +++ b/libavcodec/opus.c
> @@ -338,7 +338,7 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
>  
>      s->gain_i = AV_RL16(extradata + 16);
>      if (s->gain_i)
> -        s->gain = pow(10, s->gain_i / (20.0 * 256));
> +        s->gain = powf(10, s->gain_i / (20.0f * 256));

Changes the calculation from double to float? I don't know the code,
but even if the final type is float, double intermediate precision
might be needed. At least it's not harmful.

>  
>      map_type = extradata[18];
>      if (!map_type) {
> diff --git a/libavcodec/rdft.c b/libavcodec/rdft.c
> index 218dd4c..b017d42 100644
> --- a/libavcodec/rdft.c
> +++ b/libavcodec/rdft.c
> @@ -59,8 +59,8 @@ static void rdft_calc_c(RDFTContext *s, FFTSample *data)
>      int i, i1, i2;
>      FFTComplex ev, od;
>      const int n = 1 << s->nbits;
> -    const float k1 = 0.5;
> -    const float k2 = 0.5 - s->inverse;
> +    const float k1 = 0.5f;
> +    const float k2 = 0.5f - s->inverse;

The old code is harmless. Maybe the change would help the compiler?

>      const FFTSample *tcos = s->tcos;
>      const FFTSample *tsin = s->tsin;
>  
> @@ -117,7 +117,7 @@ av_cold int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans)
>      s->tsin = ff_sin_tabs[nbits]+(trans == DFT_R2C || trans == DFT_C2R)*(n>>2);
>  #if !CONFIG_HARDCODED_TABLES
>      for (i = 0; i < (n>>2); i++) {
> -        s->tsin[i] = sin(i*theta);
> +        s->tsin[i] = (FFTSample)sin(i*theta);

Seems pointless.

>      }
>  #endif
>      s->rdft_calc   = rdft_calc_c;
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index 9d3fcfd..351de85 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -1658,7 +1658,7 @@ int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
>      if (avctx) {
>          av_assert0(!avpkt->data || avpkt->data != avctx->internal->byte_buffer);
>          if (!avpkt->data || avpkt->size < size) {
> -            av_fast_padded_malloc(&avctx->internal->byte_buffer, &avctx->internal->byte_buffer_size, size);
> +            av_fast_padded_malloc(&avctx->internal->byte_buffer, &avctx->internal->byte_buffer_size, (size_t)size);

The range of size is actually checked above (not part of the diff
context).

>              avpkt->data = avctx->internal->byte_buffer;
>              avpkt->size = avctx->internal->byte_buffer_size;
>  #if FF_API_DESTRUCT_PACKET
> @@ -1689,10 +1689,10 @@ FF_DISABLE_DEPRECATION_WARNINGS
>  FF_ENABLE_DEPRECATION_WARNINGS
>  #endif
>          avpkt->buf      = buf;
> -        avpkt->size     = size;
> +        avpkt->size     = (int)size;

Same.

>          return 0;
>      } else {
> -        int ret = av_new_packet(avpkt, size);
> +        int ret = av_new_packet(avpkt, (int)size);

Same.

>          if (ret < 0)
>              av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size %"PRId64"\n", size);
>          return ret;
> @@ -1817,8 +1817,8 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
>                  if (avpkt->pts == AV_NOPTS_VALUE)
>                      avpkt->pts = frame->pts;
>                  if (!avpkt->duration)
> -                    avpkt->duration = ff_samples_to_time_base(avctx,
> -                                                              frame->nb_samples);
> +                    avpkt->duration = (int)ff_samples_to_time_base(avctx,
> +                                                                   frame->nb_samples);

Possibly a real issue; depends if there audio codecs which can have
unbounded frame size. While ff_samples_to_time_base() should be
checking for overflows, its return value is int64_t, and duration is
int.

>              }
>              avpkt->dts = avpkt->pts;
>          } else {
> @@ -1914,7 +1914,7 @@ int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx,
>                  av_frame_free(&frame);
>                  return AVERROR(EINVAL);
>              }
> -            frame->nb_samples = nb_samples;
> +            frame->nb_samples = (int)nb_samples;

Explicitly range-checked just above.

>          }
>  
>          /* it is assumed that the samples buffer is large enough based on the
> @@ -2651,8 +2651,9 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
>              if (sub->num_rects && !sub->end_display_time && avpkt->duration &&
>                  avctx->pkt_timebase.num) {
>                  AVRational ms = { 1, 1000 };
> -                sub->end_display_time = av_rescale_q(avpkt->duration,
> -                                                     avctx->pkt_timebase, ms);
> +                // !!! Is this cast safe?
> +                sub->end_display_time = (uint32_t)av_rescale_q(avpkt->duration,
> +                                                               avctx->pkt_timebase, ms);

This might be a real issue. Although what this code does looks
extremely questionable to me (using packet duration if sub decoder
doesn't set duration).

Best fix might be checking and fixing the return value's range with an
av_clip (the 64 bit variant, or so).

>              }
>  
>              for (i = 0; i < sub->num_rects; i++) {
> @@ -2956,7 +2957,7 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
>                           display_aspect_ratio.num, display_aspect_ratio.den);
>              }
>              if (av_log_get_level() >= AV_LOG_DEBUG) {
> -                int g = av_gcd(enc->time_base.num, enc->time_base.den);
> +                int g = (int)av_gcd(enc->time_base.num, enc->time_base.den);
>                  snprintf(buf + strlen(buf), buf_size - strlen(buf),
>                           ", %d/%d",
>                           enc->time_base.num / g, enc->time_base.den / g);

Don't know... I guess possible in theory.

> @@ -2981,7 +2982,7 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
>          break;
>      case AVMEDIA_TYPE_DATA:
>          if (av_log_get_level() >= AV_LOG_DEBUG) {
> -            int g = av_gcd(enc->time_base.num, enc->time_base.den);
> +            int g = (int)av_gcd(enc->time_base.num, enc->time_base.den);
>              if (g)
>                  snprintf(buf + strlen(buf), buf_size - strlen(buf),
>                           ", %d/%d",

Same.

> diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c
> index 87d1bbb..fc95dc6 100644
> --- a/libavcodec/vorbisdec.c
> +++ b/libavcodec/vorbisdec.c
> @@ -181,7 +181,8 @@ static float vorbisfloat2float(unsigned val)
>      long exp    = (val & 0x7fe00000L) >> 21;
>      if (val & 0x80000000)
>          mant = -mant;
> -    return ldexp(mant, exp - 20 - 768);
> +    // !!! Should this use ldexpf() (and change |mant| to float)?
> +    return (float)ldexp(mant, exp - 20 - 768);

Well, the input apparently needs to be double (uses more bits than a
float mantissa could carry), but on the other hand float might be good
enough for the final result - so probably not an issue.

>  }
>  
>  
> @@ -850,8 +851,8 @@ static int create_map(vorbis_context *vc, unsigned floor_number)
>          vf  = &floors[floor_number].data.t0;
>  
>          for (idx = 0; idx < n; ++idx) {
> -            map[idx] = floor(BARK((vf->rate * idx) / (2.0f * n)) *
> -                             (vf->bark_map_size / BARK(vf->rate / 2.0f)));
> +            map[idx] = (int32_t)floor(BARK((vf->rate * idx) / (2.0f * n)) *
> +                                      (vf->bark_map_size / BARK(vf->rate / 2.0f)));

I have no clue. This is some weird code.

>              if (vf->bark_map_size-1 < map[idx])
>                  map[idx] = vf->bark_map_size - 1;
>          }
> @@ -1131,10 +1132,10 @@ static int vorbis_floor0_decode(vorbis_context *vc,
>          {
>              int i;
>              int order = vf->order;
> -            float wstep = M_PI / vf->bark_map_size;
> +            float wstep = (float)(M_PI / vf->bark_map_size);

Useless cast.

>  
>              for (i = 0; i < order; i++)
> -                lsp[i] = 2.0f * cos(lsp[i]);
> +                lsp[i] = 2.0f * cosf(lsp[i]);

No real issue, but might be ok (maybe it would be faster?).

But do note that the float functions (f suffix) are a newer thing. It's
possible that it was avoided for compatibility.

>  
>              av_dlog(NULL, "floor0 synth: map_size = %"PRIu32"; m = %d; wstep = %f\n",
>                      vf->map_size[blockflag], order, wstep);
> @@ -1144,7 +1145,7 @@ static int vorbis_floor0_decode(vorbis_context *vc,
>                  int j, iter_cond = vf->map[blockflag][i];
>                  float p = 0.5f;
>                  float q = 0.5f;
> -                float two_cos_w = 2.0f * cos(wstep * iter_cond); // needed all times
> +                float two_cos_w = 2.0f * cosf(wstep * iter_cond); // needed all times

Same.

>  
>                  /* similar part for the q and p products */
>                  for (j = 0; j + 1 < order; j += 2) {
> @@ -1163,9 +1164,9 @@ static int vorbis_floor0_decode(vorbis_context *vc,
>                  }
>  
>                  /* calculate linear floor value */
> -                q = exp((((amplitude*vf->amplitude_offset) /
> -                          (((1 << vf->amplitude_bits) - 1) * sqrt(p + q)))
> -                         - vf->amplitude_offset) * .11512925f);
> +                q = expf((((amplitude*vf->amplitude_offset) /
> +                           (((1 << vf->amplitude_bits) - 1) * sqrtf(p + q)))
> +                          - vf->amplitude_offset) * .11512925f);

Same.

>  
>                  /* fill vector */
>                  do {
> diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
> index 4a72d0d..a79ea21 100644
> --- a/libavcodec/vp3.c
> +++ b/libavcodec/vp3.c
> @@ -1788,9 +1788,10 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx)
>          for (i = 0; i < 64; i++) {
>              s->coded_dc_scale_factor[i] = vp31_dc_scale_factor[i];
>              s->coded_ac_scale_factor[i] = vp31_ac_scale_factor[i];
> -            s->base_matrix[0][i]        = vp31_intra_y_dequant[i];
> -            s->base_matrix[1][i]        = vp31_intra_c_dequant[i];
> -            s->base_matrix[2][i]        = vp31_inter_dequant[i];
> +            // !!! Are these casts safe?
> +            s->base_matrix[0][i]        = (uint8_t)vp31_intra_y_dequant[i];
> +            s->base_matrix[1][i]        = (uint8_t)vp31_intra_c_dequant[i];
> +            s->base_matrix[2][i]        = (uint8_t)vp31_inter_dequant[i];
>              s->filter_limit_values[i]   = vp31_filter_limit_values[i];

This looks like setup from static tables, so there's probably no issue,
and the casts are useless.

>          }
>  
> diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> index 9795ba4..8fe7dcd 100644
> --- a/libavformat/aviobuf.c
> +++ b/libavformat/aviobuf.c
> @@ -850,7 +850,7 @@ int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char **bufp, int buf_si
>          return AVERROR(EINVAL);
>      }
>  
> -    overlap = buf_size - buffer_start;
> +    overlap = buf_size - (int)buffer_start;
>      new_size = buf_size + buffer_size - overlap;

Not too sure about this. It seems this assumes that the buffer is never
larger than 2GB, which in practice is usually true, but who knows what
corner cases arise. All these variables should be changed to ptrdiff_t
(including the ones you probably missed).

>  
>      alloc_size = FFMAX(s->buffer_size, new_size);
> @@ -1046,7 +1046,7 @@ static int64_t dyn_buf_seek(void *opaque, int64_t offset, int whence)
>          offset += d->size;
>      if (offset < 0 || offset > 0x7fffffffLL)
>          return -1;
> -    d->pos = offset;
> +    d->pos = (int)offset;

This is checked above (ffmpeg assumes 32 bit ints anyway).

>      return 0;
>  }
>  
> diff --git a/libavformat/cutils.c b/libavformat/cutils.c
> index 0458a2d..17acb9b 100644
> --- a/libavformat/cutils.c
> +++ b/libavformat/cutils.c
> @@ -31,11 +31,11 @@ struct tm *ff_brktimegm(time_t secs, struct tm *tm)
>      int days, y, ny, m;
>      int md[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
>  
> -    days = secs / 86400;
> +    days = (int)(secs / 86400);
>      secs %= 86400;
> -    tm->tm_hour = secs / 3600;
> +    tm->tm_hour =(int)(secs / 3600);

There might be some theoretical overflows hidden there. Also depends
for what this function is used at all. But casting to int doesn't make
these issues go away.

>      tm->tm_min = (secs % 3600) / 60;
> -    tm->tm_sec =  secs % 60;
> +    tm->tm_sec = secs % 60;

Accidental cosmetic change.

>  
>      /* oh well, may be someone some day will invent a formula for this stuff */
>      y = 1970; /* start "guessing" */
> diff --git a/libavformat/internal.h b/libavformat/internal.h
> index 3011706..b76b81a 100644
> --- a/libavformat/internal.h
> +++ b/libavformat/internal.h
> @@ -285,6 +285,7 @@ int64_t ff_gen_search(AVFormatContext *s, int stream_index,
>   * @param pts_num time base numerator
>   * @param pts_den time base denominator
>   */
> +// !!! Should |pts_num| and |pts_den| be uint64_t?
>  void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits,
>                           unsigned int pts_num, unsigned int pts_den);

That's probably not needed. Callers should check them though, if the
timebase really depends on input data.

> diff --git a/libavformat/isom.c b/libavformat/isom.c
> index d768c32..a5c43be 100644
> --- a/libavformat/isom.c
> +++ b/libavformat/isom.c
> @@ -576,7 +576,7 @@ void ff_mov_write_chan(AVIOContext *pb, int64_t channel_layout)
>          avio_wb32(pb, 0);          // mChannelBitmap
>      } else {
>          avio_wb32(pb, 0x10000);    // kCAFChannelLayoutTag_UseChannelBitmap
> -        avio_wb32(pb, channel_layout);
> +        avio_wb32(pb, (unsigned int)channel_layout);

The writing application might be able to set an invalid channel layout.
I don't know if that's checked; if it isn't, there might be a deeper
issue here. Someone should analyze it further.

>      }
>      avio_wb32(pb, 0);              // mNumberChannelDescriptions
>  }
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index 75a8a5a..48259bd 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -940,7 +940,7 @@ static int ebml_parse(MatroskaDemuxContext *matroska, EbmlSyntax *syntax,
>          int res = ebml_read_num(matroska, matroska->ctx->pb, 4, &id);
>          if (res < 0)
>              return res;
> -        matroska->current_id = id | 1 << 7 * res;
> +        matroska->current_id = (uint32_t)id | 1 << 7 * res;

The parameter 4 to ebml_read_num() already ensures it's within 32 bit
boundaries, so this is a useless cast.

>      }
>      return ebml_parse_id(matroska, syntax, matroska->current_id, data);
>  }
> @@ -1021,20 +1021,20 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska,
>  
>      switch (syntax->type) {
>      case EBML_UINT:
> -        res = ebml_read_uint(pb, length, data);
> +        res = ebml_read_uint(pb, (int)length, data);
>          break;
>      case EBML_SINT:
> -        res = ebml_read_sint(pb, length, data);
> +        res = ebml_read_sint(pb, (int)length, data);
>          break;
>      case EBML_FLOAT:
> -        res = ebml_read_float(pb, length, data);
> +        res = ebml_read_float(pb, (int)length, data);
>          break;
>      case EBML_STR:
>      case EBML_UTF8:
> -        res = ebml_read_ascii(pb, length, data);
> +        res = ebml_read_ascii(pb, (int)length, data);
>          break;
>      case EBML_BIN:
> -        res = ebml_read_binary(pb, length, data);
> +        res = ebml_read_binary(pb, (int)length, data);

This uses complicated trickery with max_lengths above this code to
exclude invalid lengths. But I'm not sure if they catch everything. For
simplification, all these functions should probably take uint64_t, so
that reasoning about this isn't needed.

>          break;
>      case EBML_NEST:
>          if ((res = ebml_read_master(matroska, length)) < 0)
> @@ -1047,7 +1047,7 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska,
>      case EBML_STOP:
>          return 1;
>      default:
> -        if (ffio_limit(pb, length) != length)
> +        if (ffio_limit(pb, (int)length) != length)
>              return AVERROR(EIO);

This is probably a real issue. The cast doesn't fix it.

>          return avio_skip(pb, length) < 0 ? AVERROR(EIO) : 0;
>      }
> @@ -1302,8 +1302,8 @@ static void matroska_fix_ass_packet(MatroskaDemuxContext *matroska,
>          ;
>      if (*ptr == ',') {
>          int64_t end_pts = pkt->pts + display_duration;
> -        int sc = matroska->time_scale * pkt->pts / 10000000;
> -        int ec = matroska->time_scale * end_pts  / 10000000;
> +        int sc = (int)(matroska->time_scale * pkt->pts / 10000000);
> +        int ec = (int)(matroska->time_scale * end_pts  / 10000000);

Might be a real issue (dunno), but it's in already disabled code, isn't
it?

>          int sh, sm, ss, eh, em, es, len;
>          sh     = sc / 360000;
>          sc    -= 360000 * sh;
> @@ -1500,7 +1500,7 @@ static void matroska_add_index_entries(MatroskaDemuxContext *matroska)
>  {
>      EbmlList *index_list;
>      MatroskaIndex *index;
> -    int index_scale = 1;
> +    uint64_t index_scale = 1;

Can't hurt.

>      int i, j;
>  
>      index_list = &matroska->index;
> @@ -1515,7 +1515,7 @@ static void matroska_add_index_entries(MatroskaDemuxContext *matroska)
>          MatroskaIndexPos *pos = pos_list->elem;
>          for (j = 0; j < pos_list->nb_elem; j++) {
>              MatroskaTrack *track = matroska_find_track_by_num(matroska,
> -                                                              pos[j].track);
> +                                                              (int)pos[j].track);

The matroska_find_track_by_num function should be fixed instead.
Although this is probably a relatively harmless corner case.

>              if (track && track->stream)
>                  av_add_index_entry(track->stream,
>                                     pos[j].pos + matroska->segment_start,
> @@ -1551,7 +1551,7 @@ static int matroska_aac_profile(char *codec_id)
>      return profile + 1;
>  }
>  
> -static int matroska_aac_sri(int samplerate)
> +static int matroska_aac_sri(double samplerate)



>  {
>      int sri;
>  
> @@ -1663,7 +1663,7 @@ static int matroska_parse_tracks(AVFormatContext *s)
>  
>          if (track->type == MATROSKA_TRACK_TYPE_VIDEO) {
>              if (!track->default_duration && track->video.frame_rate > 0)
> -                track->default_duration = 1000000000 / track->video.frame_rate;
> +                track->default_duration = (uint64_t)(1000000000 / track->video.frame_rate);

I wonder about this. I forgot what happens when out of bound float
values are converted to unsigned integers. Would the cast actually
change anything?

>              if (track->video.display_width == -1)
>                  track->video.display_width = track->video.pixel_width;
>              if (track->video.display_height == -1)
> @@ -1824,7 +1824,7 @@ static int matroska_parse_tracks(AVFormatContext *s)
>              if (!extradata)
>                  return AVERROR(ENOMEM);
>              extradata[0] = (profile << 3) | ((sri & 0x0E) >> 1);
> -            extradata[1] = ((sri & 0x01) << 7) | (track->audio.channels << 3);
> +            extradata[1] = ((sri & 0x01) << 7) | ((uint8_t)track->audio.channels << 3);

Probably pointless. channels is already unsigned.

>              if (strstr(track->codec_id, "SBR")) {
>                  sri            = matroska_aac_sri(track->audio.out_samplerate);
>                  extradata[2]   = 0x56;
> @@ -1856,14 +1856,14 @@ static int matroska_parse_tracks(AVFormatContext *s)
>                                NULL, NULL, NULL, NULL);
>              avio_write(&b, "TTA1", 4);
>              avio_wl16(&b, 1);
> -            avio_wl16(&b, track->audio.channels);
> -            avio_wl16(&b, track->audio.bitdepth);
> +            avio_wl16(&b, (unsigned int)track->audio.channels);
> +            avio_wl16(&b, (unsigned int)track->audio.bitdepth);

Same.

>              if (track->audio.out_samplerate < 0 || track->audio.out_samplerate > INT_MAX)
>                  return AVERROR_INVALIDDATA;
> -            avio_wl32(&b, track->audio.out_samplerate);
> -            avio_wl32(&b, av_rescale((matroska->duration * matroska->time_scale),
> -                                     track->audio.out_samplerate,
> -                                     AV_TIME_BASE * 1000));
> +            avio_wl32(&b, (unsigned int)track->audio.out_samplerate);
> +            avio_wl32(&b, (unsigned int)av_rescale((int64_t)(matroska->duration * matroska->time_scale),
> +                                                   (int64_t)track->audio.out_samplerate,
> +                                                   AV_TIME_BASE * 1000));

float->unsigned again, not sure.

>          } else if (codec_id == AV_CODEC_ID_RV10 ||
>                     codec_id == AV_CODEC_ID_RV20 ||
>                     codec_id == AV_CODEC_ID_RV30 ||
> @@ -1926,7 +1926,7 @@ static int matroska_parse_tracks(AVFormatContext *s)
>  
>          if (track->time_scale < 0.01)
>              track->time_scale = 1.0;
> -        avpriv_set_pts_info(st, 64, matroska->time_scale * track->time_scale,
> +        avpriv_set_pts_info(st, 64, (unsigned int)(matroska->time_scale * track->time_scale),
>                              1000 * 1000 * 1000);    /* 64 bit pts in ns */

Should possibly be checked. (Also what's with that random time_scale
check in the diff context? Looks weird.)

>  
>          /* convert the delay from ns to the track timebase */
> @@ -1965,8 +1965,8 @@ static int matroska_parse_tracks(AVFormatContext *s)
>              st->codec->codec_tag  = fourcc;
>              if (bit_depth >= 0)
>                  st->codec->bits_per_coded_sample = bit_depth;
> -            st->codec->width      = track->video.pixel_width;
> -            st->codec->height     = track->video.pixel_height;
> +            st->codec->width      = (int)track->video.pixel_width;
> +            st->codec->height     = (int)track->video.pixel_height;

Maybe best to cast to unsigned short or just av_clip...?

>              av_reduce(&st->sample_aspect_ratio.num,
>                        &st->sample_aspect_ratio.den,
>                        st->codec->height * track->video.display_width,
> @@ -2015,22 +2015,22 @@ static int matroska_parse_tracks(AVFormatContext *s)
>              }
>          } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
>              st->codec->codec_type  = AVMEDIA_TYPE_AUDIO;
> -            st->codec->sample_rate = track->audio.out_samplerate;
> -            st->codec->channels    = track->audio.channels;
> +            st->codec->sample_rate = (int)track->audio.out_samplerate;
> +            st->codec->channels    = (int)track->audio.channels;
>              if (!st->codec->bits_per_coded_sample)
> -                st->codec->bits_per_coded_sample = track->audio.bitdepth;
> +                st->codec->bits_per_coded_sample = (int)track->audio.bitdepth;
>              if (st->codec->codec_id != AV_CODEC_ID_AAC)
>                  st->need_parsing = AVSTREAM_PARSE_HEADERS;
>              if (track->codec_delay > 0) {
> -                st->codec->delay = av_rescale_q(track->codec_delay,
> -                                                st->time_base,
> -                                                (AVRational){1, st->codec->sample_rate});
> +                st->codec->delay = (int)av_rescale_q(track->codec_delay,
> +                                                     st->time_base,
> +                                                     (AVRational){1, st->codec->sample_rate});
>              }
>              if (track->seek_preroll > 0) {
>                  av_codec_set_seek_preroll(st->codec,
> -                                          av_rescale_q(track->seek_preroll,
> -                                                       (AVRational){1, 1000000000},
> -                                                       (AVRational){1, st->codec->sample_rate}));
> +                                          (int)av_rescale_q(track->seek_preroll,
> +                                                            (AVRational){1, 1000000000},
> +                                                            (AVRational){1, st->codec->sample_rate}));

All the same.

>              }
>          } else if (codec_id == AV_CODEC_ID_WEBVTT) {
>              st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
> @@ -2164,7 +2164,7 @@ static int matroska_read_header(AVFormatContext *s)
>          if (chapters[i].start != AV_NOPTS_VALUE && chapters[i].uid &&
>              (max_start == 0 || chapters[i].start > max_start)) {
>              chapters[i].chapter =
> -                avpriv_new_chapter(s, chapters[i].uid,
> +                avpriv_new_chapter(s, (int)chapters[i].uid,

This looks very wrong. avpriv_new_chapter() should probably be extended
to fix this.

>                                     (AVRational) { 1, 1000000000 },
>                                     chapters[i].start, chapters[i].end,
>                                     chapters[i].title);
> @@ -2306,12 +2306,13 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf,
>          }
>          data += n;
>          size -= n;
> -        total = lace_size[0] = num;
> +        lace_size[0] = (uint32_t)num;
> +        total = num;

Useless cast; it's checked above.

>          for (n = 1; res == 0 && n < *laces - 1; n++) {
>              int64_t snum;
>              int r;
>              r = matroska_ebmlnum_sint(matroska, data, size, &snum);
> -            if (r < 0 || lace_size[n - 1] + snum > (uint64_t)INT_MAX) {
> +            if (r < 0 || lace_size[n - 1] + snum > INT_MAX) {

Shouldn't this be just fine? snum is already uint64_t, so I'd expect the
comparison is done in uint64_t.

>                  av_log(matroska->ctx, AV_LOG_INFO,
>                         "EBML block data error\n");
>                  res = r<0 ? r : AVERROR_INVALIDDATA;
> @@ -2319,14 +2320,14 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf,
>              }
>              data        += r;
>              size        -= r;
> -            lace_size[n] = lace_size[n - 1] + snum;
> +            lace_size[n] = lace_size[n - 1] + (int)snum;

Overflows are already excluded here (and again, a cast wouldn't fix it).

>              total       += lace_size[n];
>          }
>          if (size <= total) {
>              res = AVERROR_INVALIDDATA;
>              break;
>          }
> -        lace_size[*laces - 1] = size - total;
> +        lace_size[*laces - 1] = (uint32_t)(size - total);

Probably same.

>          break;
>      }
>      }
> @@ -2595,7 +2596,7 @@ static int matroska_parse_webvtt(MatroskaDemuxContext *matroska,
>      // Do we need this for subtitles?
>      // pkt->dts = timecode;
>  
> -    pkt->duration = duration;
> +    pkt->duration = (int)duration;

I think duration can easily exceed this, and AVPacket.duration is
simply too small. We should fix this on the next bump or so.

But do note that AVPacket.convergence_duration was introduced as
extremely bad hack to fix this. Since webvtt duration probably can
exceed int, not setting this field is a bug.

>      pkt->pos = pos;
>  
>      dynarray_add(&matroska->packets, &matroska->num_packets, pkt);
> @@ -2685,9 +2686,9 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska,
>              return AVERROR(ENOMEM);
>          }
>          AV_WL32(side_data, 0);
> -        AV_WL32(side_data + 4, av_rescale_q(discard_padding,
> -                                            (AVRational){1, 1000000000},
> -                                            (AVRational){1, st->codec->sample_rate}));
> +        AV_WL32(side_data + 4, (uint32_t)av_rescale_q(discard_padding,
> +                                                      (AVRational){1, 1000000000},
> +                                                      (AVRational){1, st->codec->sample_rate}));

Same as many others.

>      }
>  
>      if (track->ms_compat)
> @@ -2716,7 +2717,7 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska,
>           * If it's a subtitle track and duration value does
>           * not overflow a uint32, then also store it normally.
>           */
> -        pkt->duration = lace_duration;
> +        pkt->duration = (int)lace_duration;

Already checked in the code above.

>      }
>  
>  #if FF_API_ASS_SSA
> @@ -2769,7 +2770,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data,
>      data += n;
>      size -= n;
>  
> -    track = matroska_find_track_by_num(matroska, num);
> +    track = matroska_find_track_by_num(matroska, (int)num);

matroska_find_track_by_num() should be fixed instead,

>      if (!track || !track->stream) {
>          av_log(matroska->ctx, AV_LOG_INFO,
>                 "Invalid stream %"PRIu64" or size %u\n", num, size);
> diff --git a/libavformat/mux.c b/libavformat/mux.c
> index 55add43..bef7f3f 100644
> --- a/libavformat/mux.c
> +++ b/libavformat/mux.c
> @@ -467,7 +467,7 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt)
>      if (pkt->duration == 0) {
>          ff_compute_frame_duration(&num, &den, st, NULL, pkt);
>          if (den && num) {
> -            pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den * st->codec->ticks_per_frame, den * (int64_t)st->time_base.num);
> +            pkt->duration = (int)av_rescale(1, num * (int64_t)st->time_base.den * st->codec->ticks_per_frame, den * (int64_t)st->time_base.num);

Not sure what to do with this, looks like there are several possible
overflows anyway?

>          }
>      }
>  
> @@ -984,9 +984,9 @@ int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
>                                       src->streams[pkt->stream_index]->time_base,
>                                       dst->streams[dst_stream]->time_base);
>      if (pkt->duration)
> -        local_pkt.duration = av_rescale_q(pkt->duration,
> -                                          src->streams[pkt->stream_index]->time_base,
> -                                          dst->streams[dst_stream]->time_base);
> +        local_pkt.duration = (int)av_rescale_q(pkt->duration,
> +                                               src->streams[pkt->stream_index]->time_base,
> +                                               dst->streams[dst_stream]->time_base);

OK, AVPacket.duration should just be fixed with the next bump or so.
This would get rid of all issues, and I'd say we should just not touch
it until this is done.

>  
>      if (interleave) ret = av_interleaved_write_frame(dst, &local_pkt);
>      else            ret = av_write_frame(dst, &local_pkt);
> @@ -1013,7 +1013,7 @@ static int av_write_uncoded_frame_internal(AVFormatContext *s, int stream_index,
>          pkt.size         = UNCODED_FRAME_PACKET_SIZE;
>          pkt.pts          =
>          pkt.dts          = frame->pts;
> -        pkt.duration     = av_frame_get_pkt_duration(frame);
> +        pkt.duration     = (int)av_frame_get_pkt_duration(frame);

...

>          pkt.stream_index = stream_index;
>          pkt.flags |= AV_PKT_FLAG_UNCODED_FRAME;
>      }
> diff --git a/libavformat/oggparseogm.c b/libavformat/oggparseogm.c
> index 54024e0..71a07cd 100644
> --- a/libavformat/oggparseogm.c
> +++ b/libavformat/oggparseogm.c
> @@ -90,12 +90,12 @@ ogm_header(AVFormatContext *s, int idx)
>          if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){
>              st->codec->width = bytestream2_get_le32(&p);
>              st->codec->height = bytestream2_get_le32(&p);
> -            avpriv_set_pts_info(st, 64, time_unit, spu * 10000000);
> +            avpriv_set_pts_info(st, 64, (unsigned int)time_unit, (unsigned int)spu * 10000000);

Might be good to do.

>          } else {
>              st->codec->channels = bytestream2_get_le16(&p);
>              bytestream2_skip(&p, 2); /* block_align */
>              st->codec->bit_rate = bytestream2_get_le32(&p) * 8;
> -            st->codec->sample_rate = spu * 10000000 / time_unit;
> +            st->codec->sample_rate = (unsigned int)(spu * 10000000 / time_unit);

Same.

>              avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
>              if (size >= 56 && st->codec->codec_id == AV_CODEC_ID_AAC) {
>                  bytestream2_skip(&p, 4);
> @@ -141,7 +141,7 @@ ogm_dshow_header(AVFormatContext *s, int idx)
>  
>          st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
>          st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, AV_RL32(p + 68));
> -        avpriv_set_pts_info(st, 64, AV_RL64(p + 164), 10000000);
> +        avpriv_set_pts_info(st, 64, (unsigned int)AV_RL64(p + 164), 10000000);

Same.

>          st->codec->width = AV_RL32(p + 176);
>          st->codec->height = AV_RL32(p + 180);
>      } else if(t == 0x05589f81){
> diff --git a/libavformat/oggparseopus.c b/libavformat/oggparseopus.c
> index c8b02fa..8527a54 100644
> --- a/libavformat/oggparseopus.c
> +++ b/libavformat/oggparseopus.c
> @@ -68,8 +68,8 @@ static int opus_header(AVFormatContext *avf, int idx)
>  
>          st->codec->sample_rate = 48000;
>          av_codec_set_seek_preroll(st->codec,
> -                                  av_rescale(OPUS_SEEK_PREROLL_MS,
> -                                             st->codec->sample_rate, 1000));
> +                                  (int)av_rescale(OPUS_SEEK_PREROLL_MS,
> +                                                  st->codec->sample_rate, 1000));
>          avpriv_set_pts_info(st, 64, 1, 48000);
>          priv->need_comments = 1;
>          return 1;
> @@ -161,8 +161,8 @@ static int opus_packet(AVFormatContext *avf, int idx)
>          int64_t skip = priv->cur_dts - os->granule + priv->pre_skip;
>          skip = FFMIN(skip, os->pduration);
>          if (skip > 0) {
> -            os->pduration = skip < os->pduration ? os->pduration - skip : 1;
> -            os->end_trimming = skip;
> +            os->pduration = skip < os->pduration ? os->pduration - (unsigned int)skip : 1;
> +            os->end_trimming = (int)skip;

Looks like skip is range checked above; useless cast.

>              av_log(avf, AV_LOG_DEBUG,
>                     "Last packet was truncated to %d due to end trimming.\n",
>                     os->pduration);
> diff --git a/libavformat/oggparsespeex.c b/libavformat/oggparsespeex.c
> index 9b5c65f..5511656 100644
> --- a/libavformat/oggparsespeex.c
> +++ b/libavformat/oggparsespeex.c
> @@ -111,8 +111,8 @@ static int speex_packet(AVFormatContext *s, int idx)
>          /* first packet of final page. we have to calculate the final packet
>             duration here because it is the only place we know the next-to-last
>             granule position. */
> -        spxp->final_packet_duration = os->granule - os->lastpts -
> -                                      packet_size * (ogg_page_packets(os) - 1);
> +        spxp->final_packet_duration = (int)(os->granule - os->lastpts -
> +                                            packet_size * (ogg_page_packets(os) - 1));

Possibly an issue, but cast is not a solution.

>      }
>  
>      if (!os->lastpts && os->granule > 0)
> diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
> index 5e34be5..79a944c 100644
> --- a/libavformat/oggparsevorbis.c
> +++ b/libavformat/oggparsevorbis.c
> @@ -400,13 +400,14 @@ static int vorbis_packet(AVFormatContext *s, int idx)
>      struct ogg *ogg = s->priv_data;
>      struct ogg_stream *os = ogg->streams + idx;
>      struct oggvorbis_private *priv = os->private;
> -    int duration, flags = 0;
> +    int flags = 0;
>  
>      /* first packet handling
>       * here we parse the duration of each packet in the first page and compare
>       * the total duration to the page granule to find the encoder delay and
>       * set the first timestamp */
>      if ((!os->lastpts || os->lastpts == AV_NOPTS_VALUE) && !(os->flags & OGG_FLAG_EOS) && (int64_t)os->granule>=0) {
> +        uint64_t duration;
>          int seg, d;
>          uint8_t *last_pkt  = os->buf + os->pstart;
>          uint8_t *next_pkt  = last_pkt;
> @@ -456,6 +457,7 @@ static int vorbis_packet(AVFormatContext *s, int idx)
>  
>      /* parse packet duration */
>      if (os->psize > 0) {
> +        int duration;
>          duration = avpriv_vorbis_parse_frame_flags(&priv->vp, os->buf + os->pstart, 1, &flags);

Didn't particularly check; probably ok to apply the duration thing.

>          if (duration < 0) {
>              os->pflags |= AV_PKT_FLAG_CORRUPT;
> @@ -477,7 +479,7 @@ static int vorbis_packet(AVFormatContext *s, int idx)
>              priv->final_duration = 0;
>          }
>          if (os->segp == os->nsegs)
> -            os->pduration = os->granule - priv->final_pts - priv->final_duration;
> +            os->pduration = (unsigned int)(os->granule - priv->final_pts - priv->final_duration);

Might be ok.

>          priv->final_duration += os->pduration;
>      }
>  
> diff --git a/libavformat/pcm.c b/libavformat/pcm.c
> index a57a4b6..aa3c067 100644
> --- a/libavformat/pcm.c
> +++ b/libavformat/pcm.c
> @@ -69,6 +69,6 @@ int ff_pcm_read_seek(AVFormatContext *s,
>      /* recompute exact position */
>      st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
>      if ((ret = avio_seek(s->pb, pos + s->data_offset, SEEK_SET)) < 0)
> -        return ret;
> +        return (int)ret;

Useless cast; error codes are always in int range.

>      return 0;
>  }
> diff --git a/libavformat/riffdec.c b/libavformat/riffdec.c
> index 09fee9d..18c2972 100644
> --- a/libavformat/riffdec.c
> +++ b/libavformat/riffdec.c
> @@ -185,7 +185,7 @@ int ff_read_riff_info(AVFormatContext *s, int64_t size)
>      while ((cur = avio_tell(pb)) >= 0 &&
>             cur <= end - 8 /* = tag + size */) {
>          uint32_t chunk_code;
> -        int64_t chunk_size;
> +        unsigned int chunk_size;

Might actually be ok. Not sure why it was int64_t. Someone else should
check whether it's really ok.

>          char key[5] = { 0 };
>          char *value;
>  
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 6e828f7..02638a5 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -172,7 +172,7 @@ int ffio_limit(AVIOContext *s, int size)
>  
>          if (s->maxsize>= 0 && remaining+1 < size) {
>              av_log(NULL, remaining ? AV_LOG_ERROR : AV_LOG_DEBUG, "Truncating packet of size %d to %"PRId64"\n", size, remaining+1);
> -            size = remaining+1;
> +            size = (int)remaining+1;

Useless cast.

>          }
>      }
>      return size;
> @@ -1025,10 +1025,10 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
>          ff_compute_frame_duration(&num, &den, st, pc, pkt);
>          if (den && num) {
>              duration = (AVRational) {num, den};
> -            pkt->duration = av_rescale_rnd(1,
> -                                           num * (int64_t) st->time_base.den,
> -                                           den * (int64_t) st->time_base.num,
> -                                           AV_ROUND_DOWN);
> +            pkt->duration = (int)av_rescale_rnd(1,
> +                                                num * (int64_t) st->time_base.den,
> +                                                den * (int64_t) st->time_base.num,
> +                                                AV_ROUND_DOWN);

...

>          }
>      }
>  
> @@ -1184,10 +1184,10 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index)
>          if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
>              if (st->codec->sample_rate > 0) {
>                  out_pkt.duration =
> -                    av_rescale_q_rnd(st->parser->duration,
> -                                     (AVRational) { 1, st->codec->sample_rate },
> -                                     st->time_base,
> -                                     AV_ROUND_DOWN);
> +                    (int)av_rescale_q_rnd(st->parser->duration,
> +                                          (AVRational) { 1, st->codec->sample_rate },
> +                                          st->time_base,
> +                                          AV_ROUND_DOWN);

...

>              }
>          }
>  
> @@ -1781,7 +1781,7 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index,
>  
>      /* do the seek */
>      if ((ret = avio_seek(s->pb, pos, SEEK_SET)) < 0)
> -        return ret;
> +        return (int)ret;

Useless cast.

>  
>      ff_read_frame_flush(s);
>      ff_update_cur_dts(s, st, ts);
> @@ -1980,11 +1980,11 @@ static int seek_frame_generic(AVFormatContext *s, int stream_index,
>              av_assert0(st->index_entries);
>              ie = &st->index_entries[st->nb_index_entries - 1];
>              if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0)
> -                return ret;
> +                return (int)ret;
>              ff_update_cur_dts(s, st, ie->timestamp);
>          } else {
>              if ((ret = avio_seek(s->pb, s->data_offset, SEEK_SET)) < 0)
> -                return ret;
> +                return (int)ret;
>          }
>          for (;;) {
>              int read_status;
> @@ -2014,7 +2014,7 @@ static int seek_frame_generic(AVFormatContext *s, int stream_index,
>              return 0;
>      ie = &st->index_entries[index];
>      if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0)
> -        return ret;
> +        return (int)ret;
>      ff_update_cur_dts(s, st, ie->timestamp);
>  

All useless.

>      return 0;
> @@ -2238,7 +2238,7 @@ static void update_stream_timings(AVFormatContext *ic)
>          double bitrate = (double) filesize * 8.0 * AV_TIME_BASE /
>                           (double) ic->duration;
>          if (bitrate >= 0 && bitrate <= INT_MAX)
> -            ic->bit_rate = bitrate;
> +            ic->bit_rate = (int)bitrate;

Obviously checked, even if not: useless cast.

>      }
>  }
>  
> diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
> index 9c4e2df..a88743d 100644
> --- a/libavformat/wavdec.c
> +++ b/libavformat/wavdec.c
> @@ -61,7 +61,7 @@ typedef struct WAVDemuxContext {
>  
>  #if CONFIG_WAV_DEMUXER
>  
> -static int64_t next_tag(AVIOContext *pb, uint32_t *tag)
> +static unsigned int next_tag(AVIOContext *pb, uint32_t *tag)
>  {
>      *tag = avio_rl32(pb);
>      return avio_rl32(pb);
> @@ -76,10 +76,10 @@ static int64_t wav_seek_tag(WAVDemuxContext * wav, AVIOContext *s, int64_t offse
>  }
>  
>  /* return the size of the found tag */
> -static int64_t find_tag(WAVDemuxContext * wav, AVIOContext *pb, uint32_t tag1)
> +static unsigned int find_tag(WAVDemuxContext * wav, AVIOContext *pb, uint32_t tag1)
>  {
>      unsigned int tag;
> -    int64_t size;
> +    unsigned int size;
>  
>      for (;;) {
>          if (avio_feof(pb))
> @@ -128,7 +128,7 @@ static int wav_parse_fmt_tag(AVFormatContext *s, int64_t size, AVStream **st)
>      if (!*st)
>          return AVERROR(ENOMEM);
>  
> -    ret = ff_get_wav_header(pb, (*st)->codec, size);
> +    ret = ff_get_wav_header(pb, (*st)->codec, (int)size);
>      if (ret < 0)
>          return ret;
>      handle_stream_probing(*st);
> @@ -158,7 +158,7 @@ static inline int wav_parse_bext_string(AVFormatContext *s, const char *key,
>      return 0;
>  }
>  
> -static int wav_parse_bext_tag(AVFormatContext *s, int64_t size)
> +static int wav_parse_bext_tag(AVFormatContext *s, int size)
>  {
>      char temp[131], *coding_history;
>      int ret, x;
> @@ -331,7 +331,7 @@ static int wav_read_header(AVFormatContext *s)
>                  sample_count = avio_rl32(pb);
>              break;
>          case MKTAG('b', 'e', 'x', 't'):
> -            if ((ret = wav_parse_bext_tag(s, size)) < 0)
> +            if ((ret = wav_parse_bext_tag(s, (int)size)) < 0)
>                  return ret;
>              break;
>          case MKTAG('S','M','V','0'):
> @@ -543,7 +543,7 @@ smv_out:
>              size = st->codec->block_align;
>          size = (size / st->codec->block_align) * st->codec->block_align;
>      }
> -    size = FFMIN(size, left);
> +    size = FFMIN(size, (int)left);
>      ret  = av_get_packet(s->pb, pkt, size);
>      if (ret < 0)
>          return ret;
> @@ -566,7 +566,7 @@ static int wav_read_seek(AVFormatContext *s,
>          else
>              timestamp = av_rescale_q(smv_timestamp, s->streams[1]->time_base, s->streams[0]->time_base);
>          if (wav->smv_frames_per_jpeg > 0) {
> -            wav->smv_block = smv_timestamp / wav->smv_frames_per_jpeg;
> +            wav->smv_block = (int)(smv_timestamp / wav->smv_frames_per_jpeg);
>              wav->smv_cur_pt = smv_timestamp % wav->smv_frames_per_jpeg;
>          }
>      }

I skipped review of this file.

> diff --git a/libavutil/avstring.c b/libavutil/avstring.c
> index a63fb84..d632b2c 100644
> --- a/libavutil/avstring.c
> +++ b/libavutil/avstring.c
> @@ -369,7 +369,7 @@ int av_utf8_decode(int32_t *codep, const uint8_t **bufp, const uint8_t *buf_end,
>          goto end;
>      }
>  
> -    *codep = code;
> +    *codep = (int32_t)code;

It's range checked above; useless cast.

>  
>      if (code > 0x10FFFF &&
>          !(flags & AV_UTF8_FLAG_ACCEPT_INVALID_BIG_CODES))
> diff --git a/libavutil/bswap.h b/libavutil/bswap.h
> index 91cb795..11ae4a7 100644
> --- a/libavutil/bswap.h
> +++ b/libavutil/bswap.h
> @@ -72,7 +72,7 @@ static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
>  #ifndef av_bswap64
>  static inline uint64_t av_const av_bswap64(uint64_t x)
>  {
> -    return (uint64_t)av_bswap32(x) << 32 | av_bswap32(x >> 32);
> +    return (uint64_t)av_bswap32((uint32_t)x) << 32 | av_bswap32(x >> 32);

Not sure - the original code is fine but looks not explicit enough for
my tastes. So maybe ok.

>  }
>  #endif
>  
> diff --git a/libavutil/eval.c b/libavutil/eval.c
> index 5099e57..8566188 100644
> --- a/libavutil/eval.c
> +++ b/libavutil/eval.c
> @@ -176,7 +176,7 @@ static double eval_expr(Parser *p, AVExpr *e)
>          case e_func2:  return e->value * e->a.func2(p->opaque, eval_expr(p, e->param[0]), eval_expr(p, e->param[1]));
>          case e_squish: return 1/(1+exp(4*eval_expr(p, e->param[0])));
>          case e_gauss: { double d = eval_expr(p, e->param[0]); return exp(-d*d/2)/sqrt(2*M_PI); }
> -        case e_ld:     return e->value * p->var[av_clip(eval_expr(p, e->param[0]), 0, VARS-1)];
> +        case e_ld:     return e->value * p->var[av_clip((int)eval_expr(p, e->param[0]), 0, VARS-1)];

The correct av_clip version should be used. There are several.

>          case e_isnan:  return e->value * !!isnan(eval_expr(p, e->param[0]));
>          case e_isinf:  return e->value * !!isinf(eval_expr(p, e->param[0]));
>          case e_floor:  return e->value * floor(eval_expr(p, e->param[0]));
> @@ -202,15 +202,15 @@ static double eval_expr(Parser *p, AVExpr *e)
>          }
>          case e_print: {
>              double x = eval_expr(p, e->param[0]);
> -            int level = e->param[1] ? av_clip(eval_expr(p, e->param[1]), INT_MIN, INT_MAX) : AV_LOG_INFO;
> +            int level = e->param[1] ? (int)av_clip64((int64_t)eval_expr(p, e->param[1]), INT_MIN, INT_MAX) : AV_LOG_INFO;

Same.

>              av_log(p, level, "%f\n", x);
>              return x;
>          }
>          case e_random:{
> -            int idx= av_clip(eval_expr(p, e->param[0]), 0, VARS-1);
> -            uint64_t r= isnan(p->var[idx]) ? 0 : p->var[idx];
> +            int idx= av_clip((int)eval_expr(p, e->param[0]), 0, VARS-1);

Same.

> +            uint64_t r= isnan(p->var[idx]) ? 0 : (uint64_t)p->var[idx];

Not sure.

>              r= r*1664525+1013904223;
> -            p->var[idx]= r;
> +            p->var[idx]= (double)r;

Why does it warn?

>              return e->value * (r * (1.0/UINT64_MAX));
>          }
>          case e_while: {
> @@ -222,7 +222,7 @@ static double eval_expr(Parser *p, AVExpr *e)
>          case e_taylor: {
>              double t = 1, d = 0, v;
>              double x = eval_expr(p, e->param[1]);
> -            int id = e->param[2] ? av_clip(eval_expr(p, e->param[2]), 0, VARS-1) : 0;
> +            int id = e->param[2] ? av_clip((int)eval_expr(p, e->param[2]), 0, VARS-1) : 0;

Should use correct av_clip* fn.

>              int i;
>              double var0 = p->var[id];
>              for(i=0; i<1000; i++) {
> @@ -284,7 +284,7 @@ static double eval_expr(Parser *p, AVExpr *e)
>              double d2 = eval_expr(p, e->param[1]);
>              switch (e->type) {
>                  case e_mod: return e->value * (d - floor((!CONFIG_FTRAPV || d2) ? d / d2 : d * INFINITY) * d2);
> -                case e_gcd: return e->value * av_gcd(d,d2);
> +                case e_gcd: return e->value * av_gcd((int64_t)d,(int64_t)d2);

Seems useless.

>                  case e_max: return e->value * (d >  d2 ?   d : d2);
>                  case e_min: return e->value * (d <  d2 ?   d : d2);
>                  case e_eq:  return e->value * (d == d2 ? 1.0 : 0.0);
> @@ -297,7 +297,7 @@ static double eval_expr(Parser *p, AVExpr *e)
>                  case e_div: return e->value * ((!CONFIG_FTRAPV || d2 ) ? (d / d2) : d * INFINITY);
>                  case e_add: return e->value * (d + d2);
>                  case e_last:return e->value * d2;
> -                case e_st : return e->value * (p->var[av_clip(d, 0, VARS-1)]= d2);
> +                case e_st : return e->value * (p->var[av_clip((int)d, 0, VARS-1)]= d2);

Correct av_clip version should be used.

Wait a moment, I see all these inputs are double, but are turned into
an index of a variable. So maybe there should be a special function to
do this conversion in a checked manner.

>                  case e_hypot:return e->value * (sqrt(d*d + d2*d2));
>                  case e_bitand: return isnan(d) || isnan(d2) ? NAN : e->value * ((long int)d & (long int)d2);
>                  case e_bitor:  return isnan(d) || isnan(d2) ? NAN : e->value * ((long int)d | (long int)d2);
> diff --git a/libavutil/intfloat_readwrite.c b/libavutil/intfloat_readwrite.c
> index af5da62..e72168b 100644
> --- a/libavutil/intfloat_readwrite.c
> +++ b/libavutil/intfloat_readwrite.c
> @@ -35,13 +35,14 @@
>  double av_int2dbl(int64_t v){
>      if((uint64_t)v+v > 0xFFEULL<<52)
>          return NAN;
> -    return ldexp(((v&((1LL<<52)-1)) + (1LL<<52)) * (v>>63|1), (v>>52&0x7FF)-1075);
> +    return ldexp((double)(((v&((1LL<<52)-1)) + (1LL<<52)) * (v>>63|1)), (v>>52&0x7FF)-1075);
>  }
>  
>  float av_int2flt(int32_t v){
>      if((uint32_t)v+v > 0xFF000000U)
>          return NAN;
> -    return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150);
> +    // !!! Should this use ldexpf()?
> +    return (float)ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150);
>  }
>  
>  double av_ext2dbl(const AVExtFloat ext){
> @@ -58,7 +59,7 @@ double av_ext2dbl(const AVExtFloat ext){
>                               * single and double precision formats. */
>      if (ext.exponent[0]&0x80)
>          m= -m;
> -    return ldexp(m, e);
> +    return ldexp((double)m, e);
>  }
>  
>  int64_t av_dbl2int(double d){
> @@ -73,8 +74,8 @@ int32_t av_flt2int(float d){
>      int e;
>      if     ( !d) return 0;
>      else if(d-d) return 0x7F800000 + ((d<0)<<31) + (d!=d);
> -    d= frexp(d, &e);
> -    return (d<0)<<31 | (e+126)<<23 | (int64_t)((fabs(d)-0.5)*(1<<24));
> +    d= frexpf(d, &e);
> +    return (d<0)<<31 | (e+126)<<23 | (int32_t)((fabs(d)-0.5)*(1<<24));
>  }
>  
>  AVExtFloat av_dbl2ext(double d){
> @@ -88,7 +89,7 @@ AVExtFloat av_dbl2ext(double d){
>          ext.exponent[1] = e;
>          m = (uint64_t)ldexp(f, 64);
>          for (i=0; i < 8; i++)
> -            ext.mantissa[i] = m>>(56-(i<<3));
> +            ext.mantissa[i] = (uint8_t)(m>>(56-(i<<3)));
>      } else if (f != 0.0) {
>          ext.exponent[0] = 0x7f; ext.exponent[1] = 0xff;
>          if (!isinf(f))

All of this is too much for me right now; but note that the *f suffix
functions might have portability issues to all the weird systems ffmpeg
likes to be compatible with (I guess).

> diff --git a/libavutil/opt.c b/libavutil/opt.c
> index ca4edb8..9f9f1c5 100644
> --- a/libavutil/opt.c
> +++ b/libavutil/opt.c
> @@ -113,14 +113,14 @@ static int write_number(void *obj, const AVOption *o, void *dst, double num, int
>      case AV_OPT_TYPE_FLAGS:
>      case AV_OPT_TYPE_PIXEL_FMT:
>      case AV_OPT_TYPE_SAMPLE_FMT:
> -    case AV_OPT_TYPE_INT:   *(int       *)dst= llrint(num/den)*intnum; break;
> +    case AV_OPT_TYPE_INT:   *(int        *)dst= (int)(llrint(num/den)*intnum); break;
>      case AV_OPT_TYPE_DURATION:
>      case AV_OPT_TYPE_CHANNEL_LAYOUT:
> -    case AV_OPT_TYPE_INT64: *(int64_t   *)dst= llrint(num/den)*intnum; break;
> -    case AV_OPT_TYPE_FLOAT: *(float     *)dst= num*intnum/den;         break;
> -    case AV_OPT_TYPE_DOUBLE:*(double    *)dst= num*intnum/den;         break;
> +    case AV_OPT_TYPE_INT64: *(int64_t    *)dst= llrint(num/den)*intnum;        break;
> +    case AV_OPT_TYPE_FLOAT: *(float      *)dst= (float)num*intnum/den;         break;
> +    case AV_OPT_TYPE_DOUBLE:*(double     *)dst= num*intnum/den;                break;
>      case AV_OPT_TYPE_RATIONAL:
> -        if ((int)num == num) *(AVRational*)dst= (AVRational){num*intnum, den};
> +        if ((int)num == num) *(AVRational*)dst= (AVRational){(int)(num*intnum), den};
>          else                 *(AVRational*)dst= av_d2q(num*intnum/den, 1<<24);
>          break;
>      default:
> @@ -251,8 +251,8 @@ static int set_string_number(void *obj, void *target_obj, const AVOption *o, con
>          }
>          if (o->type == AV_OPT_TYPE_FLAGS) {
>              read_number(o, dst, NULL, NULL, &intnum);
> -            if      (cmd == '+') d = intnum | (int64_t)d;
> -            else if (cmd == '-') d = intnum &~(int64_t)d;
> +            if      (cmd == '+') d = (double)(intnum | (int64_t)d);
> +            else if (cmd == '-') d = (double)(intnum &~(int64_t)d);
>          }
>  

The float casts are probably useless, the other ones potentially
require better overflow checks (not sure).

>          if ((ret = write_number(obj, o, dst, d, 1, 1)) < 0)
> @@ -328,8 +328,8 @@ static int set_string_fmt(void *obj, const AVOption *o, const char *val, uint8_t
>          }
>      }
>  
> -    min = FFMAX(o->min, -1);
> -    max = FFMIN(o->max, fmt_nb-1);
> +    min = (int)FFMAX(o->min, -1);
> +    max = (int)FFMIN(o->max, fmt_nb-1);

I suspect they are already ranged checked, but even if not, the casts
are useless.

>  
>      // hack for compatibility with old ffmpeg
>      if(min == 0 && max == 0) {
> @@ -592,8 +592,8 @@ static int set_format(void *obj, const char *name, int fmt, int search_flags,
>          return AVERROR(EINVAL);
>      }
>  
> -    min = FFMAX(o->min, -1);
> -    max = FFMIN(o->max, nb_fmts-1);
> +    min = (int)FFMAX(o->min, -1);
> +    max = (int)FFMIN(o->max, nb_fmts-1);
>  

Same.

>      if (fmt < min || fmt > max) {
>          av_log(obj, AV_LOG_ERROR,
> @@ -627,7 +627,7 @@ int av_opt_set_channel_layout(void *obj, const char *name, int64_t cl, int searc
>                 "The value set by option '%s' is not a channel layout.\n", o->name);
>          return AVERROR(EINVAL);
>      }
> -    *(int *)(((int64_t *)target_obj) + o->offset) = cl;
> +    *(int *)(((int64_t *)target_obj) + o->offset) = (int)cl;

Same.

>      return 0;
>  }
>  
> @@ -801,7 +801,7 @@ AVRational av_get_q(void *obj, const char *name, const AVOption **o_out)
>      if (get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
>          return (AVRational){0, 0};
>      if (num == 1.0 && (int)intnum == intnum)
> -        return (AVRational){intnum, den};
> +        return (AVRational){(int)intnum, den};
>      else

Same.

>          return av_d2q(num*intnum/den, 1<<24);
>  }
> @@ -814,7 +814,7 @@ int64_t av_get_int(void *obj, const char *name, const AVOption **o_out)
>  
>      if (get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
>          return -1;
> -    return num*intnum/den;
> +    return (int64_t)(num*intnum/den);

Probably needs better checks or a better concept what to do with out of
range checks. Or it could be that these are _already_ checked somehow,
depending on how this avopt stuff is supposed to work.

>  }
>  #endif
>  
> @@ -826,7 +826,7 @@ int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_v
>  
>      if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
>          return ret;
> -    *out_val = num*intnum/den;
> +    *out_val = (int64_t)(num*intnum/den);
>      return 0;
>  }
>  
> @@ -852,7 +852,7 @@ int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_
>          return ret;
>  
>      if (num == 1.0 && (int)intnum == intnum)
> -        *out_val = (AVRational){intnum, den};
> +        *out_val = (AVRational){(int)intnum, den};
>      else
>          *out_val = av_d2q(num*intnum/den, 1<<24);
>      return 0;
> @@ -886,7 +886,7 @@ int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRatio
>          return ret;
>  
>      if (num == 1.0 && (int)intnum == intnum)
> -        *out_val = (AVRational){intnum, den};
> +        *out_val = (AVRational){(int)intnum, den};
>      else
>          *out_val = av_d2q(num*intnum/den, 1<<24);
>      return 0;
> @@ -964,7 +964,7 @@ int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
>      if (!field || !flag || flag->type != AV_OPT_TYPE_CONST ||
>          av_opt_get_int(obj, field_name, 0, &res) < 0)
>          return 0;
> -    return res & flag->default_val.i64;
> +    return (int)(res & flag->default_val.i64);
>  }
>  
>  static void log_value(void *av_log_obj, int level, double d)
> @@ -1125,7 +1125,7 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
>              case AV_OPT_TYPE_DURATION:
>              case AV_OPT_TYPE_INT:
>              case AV_OPT_TYPE_INT64:
> -                log_value(av_log_obj, AV_LOG_INFO, opt->default_val.i64);
> +                log_value(av_log_obj, AV_LOG_INFO, (double)opt->default_val.i64);
>                  break;

this and all of it above looks like the usual.

>              case AV_OPT_TYPE_DOUBLE:
>              case AV_OPT_TYPE_FLOAT:
> diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c
> index ba4b4e1..0fdce59 100644
> --- a/libavutil/parseutils.c
> +++ b/libavutil/parseutils.c
> @@ -397,7 +397,7 @@ int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen,
>      }
>  
>      if (tail) {
> -        double alpha;
> +        unsigned long alpha;
>          const char *alpha_string = tail;
>          if (!strncmp(alpha_string, "0x", 2)) {
>              alpha = strtoul(alpha_string, &tail, 16);
> @@ -406,7 +406,7 @@ int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen,
>              if (norm_alpha < 0.0 || norm_alpha > 1.0)
>                  alpha = 256;
>              else
> -                alpha = 255 * norm_alpha;
> +                alpha = (unsigned long)(255 * norm_alpha);
>          }
>  
>          if (tail == alpha_string || *tail || alpha > 255 || alpha < 0) {
> @@ -414,7 +414,7 @@ int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen,
>                     alpha_string, color_string);
>              return AVERROR(EINVAL);
>          }
> -        rgba_color[3] = alpha;
> +        rgba_color[3] = (uint8_t)alpha;

Might be ok. Not sure what it prevents.

>      }
>  
>      return 0;
> diff --git a/libavutil/rational.c b/libavutil/rational.c
> index 55a8dd5..1248230 100644
> --- a/libavutil/rational.c
> +++ b/libavutil/rational.c
> @@ -44,7 +44,7 @@ int av_reduce(int *dst_num, int *dst_den,
>          den = FFABS(den) / gcd;
>      }
>      if (num <= max && den <= max) {
> -        a1 = (AVRational) { num, den };
> +        a1 = (AVRational) { (int)num, (int)den };

Didn't check context, but probably already range checked, and the cast
is in any case useless.

>          den = 0;
>      }
>  
> @@ -59,12 +59,12 @@ int av_reduce(int *dst_num, int *dst_den,
>              if (a1.den) x = FFMIN(x, (max - a0.den) / a1.den);
>  
>              if (den * (2 * x * a1.den + a0.den) > num * a1.den)
> -                a1 = (AVRational) { x * a1.num + a0.num, x * a1.den + a0.den };
> +                a1 = (AVRational) { (int)(x * a1.num + a0.num), (int)(x * a1.den + a0.den) };

Useless casts.

>              break;
>          }
>  
>          a0  = a1;
> -        a1  = (AVRational) { a2n, a2d };
> +        a1  = (AVRational) { (int)a2n, (int)a2d };

Same.

>          num = den;
>          den = next_den;
>      }
> @@ -115,9 +115,9 @@ AVRational av_d2q(double d, int max)
>      exponent = FFMAX( (int)(log(fabs(d) + 1e-20)/LOG2), 0);
>      den = 1LL << (61 - exponent);
>      // (int64_t)rint() and llrint() do not work with gcc on ia64 and sparc64
> -    av_reduce(&a.num, &a.den, floor(d * den + 0.5), den, max);
> +    av_reduce(&a.num, &a.den, (int)floor(d * den + 0.5), den, max);
>      if ((!a.num || !a.den) && d && max>0 && max<INT_MAX)
> -        av_reduce(&a.num, &a.den, floor(d * den + 0.5), den, INT_MAX);
> +        av_reduce(&a.num, &a.den, (int)floor(d * den + 0.5), den, INT_MAX);

Useless casts; not sure if there's a problem.

>  
>      return a;
>  }
> diff --git a/libavutil/utils.c b/libavutil/utils.c
> index aafd3b9..9c187c5 100644
> --- a/libavutil/utils.c
> +++ b/libavutil/utils.c
> @@ -103,7 +103,7 @@ unsigned av_int_list_length_for_size(unsigned elsize,
>      if (!list)
>          return 0;
>  #define LIST_LENGTH(type) \
> -    { type t = term, *l = (type *)list; for (i = 0; l[i] != t; i++); }
> +    { type t = (type)term, *l = (type *)list; for (i = 0; l[i] != t; i++); }
>      switch (elsize) {
>      case 1: LIST_LENGTH(uint8_t);  break;
>      case 2: LIST_LENGTH(uint16_t); break;

My contempt for av_int_list_length_for_size() is unmeasurable, but the
cast is useless and there's probably no problem due to how this
function is used.


More information about the ffmpeg-devel mailing list