[FFmpeg-devel] [PATCH] ptrdiff_t related fixes and negative linesizes

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Fri Sep 22 20:47:55 EEST 2023


Paul B Mahol:
> diff --git a/libavcodec/gifdec.c b/libavcodec/gifdec.c
> index d90e467cac..fb0b335088 100644
> --- a/libavcodec/gifdec.c
> +++ b/libavcodec/gifdec.c
> @@ -86,26 +86,29 @@ static void gif_read_palette(GifState *s, uint32_t *pal, int nb)
>  
>  static void gif_fill(AVFrame *picture, uint32_t color)
>  {
> -    uint32_t *p = (uint32_t *)picture->data[0];
> -    uint32_t *p_end = p + (picture->linesize[0] / sizeof(uint32_t)) * picture->height;
> -
> -    for (; p < p_end; p++)
> -        *p = color;
> +    const ptrdiff_t linesize = picture->linesize[0];
> +    const uint8_t *py = picture->data[0];
> +    const int w = picture->width;
> +    const int h = picture->height;
> +
> +    for (int y = 0; y < h; y++) {
> +        uint32_t *px = (uint32_t *)py;
> +        for (int x = 0; x < w; x++)
> +            px[x] = color;
> +        py += linesize;
> +    }
>  }
>  
>  static void gif_fill_rect(AVFrame *picture, uint32_t color, int l, int t, int w, int h)
>  {
> -    const ptrdiff_t linesize = picture->linesize[0] / sizeof(uint32_t);
> -    const uint32_t *py = (uint32_t *)picture->data[0] + t * linesize;
> -    const uint32_t *pr, *pb = py + h * linesize;
> -    uint32_t *px;
> -
> -    for (; py < pb; py += linesize) {
> -        px = (uint32_t *)py + l;
> -        pr = px + w;
> -
> -        for (; px < pr; px++)
> -            *px = color;
> +    const ptrdiff_t linesize = picture->linesize[0];
> +    const uint8_t *py = picture->data[0] + t * linesize;

Don't use const if you cast it away a few lines below.

> +
> +    for (int y = 0; y < h; y++) {
> +        uint32_t *px = ((uint32_t *)py) + l;
> +        for (int x = 0; x < w; x++)
> +            px[x] = color;
> +        py += linesize;
>      }
>  }



More information about the ffmpeg-devel mailing list