summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorClément Bœsch <ubitux@gmail.com>2012-12-29 22:09:59 +0100
committerClément Bœsch <ubitux@gmail.com>2012-12-30 22:19:04 +0100
commit36e61e24e7ac737b38c4382d439329352d9e0c29 (patch)
treea3a478a143dcbb3d4d386fabfa1513487543c438 /libavformat
parente911f4ae720afe4a090ded2b165647734f0320ef (diff)
lavc: add ff_bprint_to_extradata() helper and use it.
This commit also makes sure the extradata and subtitle_header are NUL terminated, without taking into account the trailing '\0' in account in the size. At the same time, it should fix 'warning: dereferencing type-punned pointer will break strict-aliasing rules' warning for compilers who don't consider uint8_t** and char** compatibles.
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/assdec.c8
-rw-r--r--libavformat/jacosubdec.c8
-rw-r--r--libavformat/samidec.c9
-rw-r--r--libavformat/subviewerdec.c8
4 files changed, 14 insertions, 19 deletions
diff --git a/libavformat/assdec.c b/libavformat/assdec.c
index 6c4614ec47..34229cb6f9 100644
--- a/libavformat/assdec.c
+++ b/libavformat/assdec.c
@@ -22,6 +22,7 @@
#include "avformat.h"
#include "internal.h"
#include "subtitles.h"
+#include "libavcodec/internal.h"
#include "libavutil/bprint.h"
typedef struct ASSContext{
@@ -132,12 +133,9 @@ static int ass_read_header(AVFormatContext *s)
av_bprint_finalize(&line, NULL);
- av_bprint_finalize(&header, (char **)&st->codec->extradata);
- if (!st->codec->extradata) {
- res = AVERROR(ENOMEM);
+ res = ff_bprint_to_extradata(st->codec, &header);
+ if (res < 0)
goto end;
- }
- st->codec->extradata_size = header.len + 1;
ff_subtitles_queue_finalize(&ass->q);
diff --git a/libavformat/jacosubdec.c b/libavformat/jacosubdec.c
index 1c58e3bf25..153da4247a 100644
--- a/libavformat/jacosubdec.c
+++ b/libavformat/jacosubdec.c
@@ -28,6 +28,7 @@
#include "avformat.h"
#include "internal.h"
#include "subtitles.h"
+#include "libavcodec/internal.h"
#include "libavcodec/jacosub.h"
#include "libavutil/avstring.h"
#include "libavutil/bprint.h"
@@ -159,7 +160,7 @@ static int jacosub_read_header(AVFormatContext *s)
JACOsubContext *jacosub = s->priv_data;
int shift_set = 0; // only the first shift matters
int merge_line = 0;
- int i;
+ int i, ret;
AVStream *st = avformat_new_stream(s, NULL);
if (!st)
@@ -228,8 +229,9 @@ static int jacosub_read_header(AVFormatContext *s)
}
/* general/essential directives in the extradata */
- av_bprint_finalize(&header, (char **)&st->codec->extradata);
- st->codec->extradata_size = header.len + 1;
+ ret = ff_bprint_to_extradata(st->codec, &header);
+ if (ret < 0)
+ return ret;
/* SHIFT and TIMERES affect the whole script so packet timing can only be
* done in a second pass */
diff --git a/libavformat/samidec.c b/libavformat/samidec.c
index 85fd220f4a..bdde2f466f 100644
--- a/libavformat/samidec.c
+++ b/libavformat/samidec.c
@@ -27,6 +27,7 @@
#include "avformat.h"
#include "internal.h"
#include "subtitles.h"
+#include "libavcodec/internal.h"
#include "libavutil/avstring.h"
#include "libavutil/bprint.h"
#include "libavutil/intreadwrite.h"
@@ -91,13 +92,9 @@ static int sami_read_header(AVFormatContext *s)
av_bprint_clear(&buf);
}
- st->codec->extradata_size = hdr_buf.len + 1;
- av_bprint_finalize(&hdr_buf, (char **)&st->codec->extradata);
- if (!st->codec->extradata) {
- st->codec->extradata_size = 0;
- res = AVERROR(ENOMEM);
+ res = ff_bprint_to_extradata(st->codec, &hdr_buf);
+ if (res < 0)
goto end;
- }
ff_subtitles_queue_finalize(&sami->q);
diff --git a/libavformat/subviewerdec.c b/libavformat/subviewerdec.c
index 7691d82768..8ecc928817 100644
--- a/libavformat/subviewerdec.c
+++ b/libavformat/subviewerdec.c
@@ -27,6 +27,7 @@
#include "avformat.h"
#include "internal.h"
#include "subtitles.h"
+#include "libavcodec/internal.h"
#include "libavutil/avstring.h"
#include "libavutil/bprint.h"
#include "libavutil/intreadwrite.h"
@@ -99,12 +100,9 @@ static int subviewer_read_header(AVFormatContext *s)
av_bprintf(&header, "%s", line);
if (!strncmp(line, "[END INFORMATION]", 17) || !strncmp(line, "[SUBTITLE]", 10)) {
/* end of header */
- av_bprint_finalize(&header, (char **)&st->codec->extradata);
- if (!st->codec->extradata) {
- res = AVERROR(ENOMEM);
+ res = ff_bprint_to_extradata(st->codec, &header);
+ if (res < 0)
goto end;
- }
- st->codec->extradata_size = header.len + 1;
} else if (strncmp(line, "[INFORMATION]", 13)) {
/* assume file metadata at this point */
int i, j = 0;