From 29d7eef7dcfaf6cc6c97ac154e54c89f77507d86 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= <Reimar.Doeffinger@gmx.de>
Date: Thu, 20 Aug 2009 18:54:50 +0000
Subject: Always allocate a buffer of AVPALETTE_SIZE for palette in the
 subtitle decoders instead of as small as possible. This avoids completely
 unnecessary issues with e.g. libswscale.

Originally committed as revision 19673 to svn://svn.ffmpeg.org/ffmpeg/trunk
---
 libavcodec/dvbsubdec.c | 2 +-
 libavcodec/dvdsubdec.c | 3 +--
 libavcodec/xsubdec.c   | 2 +-
 3 files changed, 3 insertions(+), 4 deletions(-)

(limited to 'libavcodec')

diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index fb09740c2b..b810ef9e49 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -1314,7 +1314,7 @@ static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,
             break;
         }
 
-        rect->pict.data[1] = av_malloc((1 << region->depth) * sizeof(uint32_t));
+        rect->pict.data[1] = av_mallocz(AVPALETTE_SIZE);
         memcpy(rect->pict.data[1], clut_table, (1 << region->depth) * sizeof(uint32_t));
 
         rect->pict.data[0] = av_malloc(region->buf_size);
diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c
index 49b0802f58..142241217c 100644
--- a/libavcodec/dvdsubdec.c
+++ b/libavcodec/dvdsubdec.c
@@ -318,14 +318,13 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header,
                            buf, offset1, buf_size, is_8bit);
                 decode_rle(bitmap + w, w * 2, w, h / 2,
                            buf, offset2, buf_size, is_8bit);
+                sub_header->rects[0]->pict.data[1] = av_mallocz(AVPALETTE_SIZE);
                 if (is_8bit) {
                     if (yuv_palette == 0)
                         goto fail;
-                    sub_header->rects[0]->pict.data[1] = av_malloc(256 * 4);
                     sub_header->rects[0]->nb_colors = 256;
                     yuv_a_to_rgba(yuv_palette, alpha, (uint32_t*)sub_header->rects[0]->pict.data[1], 256);
                 } else {
-                    sub_header->rects[0]->pict.data[1] = av_malloc(4 * 4);
                     sub_header->rects[0]->nb_colors = 4;
                     guess_palette((uint32_t*)sub_header->rects[0]->pict.data[1],
                                   colormap, alpha, 0xffff00);
diff --git a/libavcodec/xsubdec.c b/libavcodec/xsubdec.c
index 3838722c1f..368caf4a6d 100644
--- a/libavcodec/xsubdec.c
+++ b/libavcodec/xsubdec.c
@@ -95,7 +95,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
     sub->rects[0]->pict.linesize[0] = w;
     sub->rects[0]->pict.data[0] = av_malloc(w * h);
     sub->rects[0]->nb_colors = 4;
-    sub->rects[0]->pict.data[1] = av_malloc(sub->rects[0]->nb_colors * 4);
+    sub->rects[0]->pict.data[1] = av_mallocz(AVPALETTE_SIZE);
 
     // read palette
     for (i = 0; i < sub->rects[0]->nb_colors; i++)
-- 
cgit v1.2.3