diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-05-30 14:11:03 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-05-30 14:18:53 +0200 |
commit | 8bedbb82cee4463a43e60eb22674c8bf927280ef (patch) | |
tree | a2c5e516bbb25d35fc0fd3b93ebcb4dc4578c28e /libavcodec/jpeg2000.c | |
parent | b3af9242d013cea1c55f20139316280596332eba (diff) | |
download | ffmpeg-8bedbb82cee4463a43e60eb22674c8bf927280ef.tar.gz |
j2k/jpeg2000: split data pointer in int & float.
This fixes a TODO item and unifies both decoders structures
It also fixes undefined behavior due to aliasing violations
I choose 2 fields instead of a union because mistakely using the
wrong type with a union will lead to hard to debug "wrong output"
while with 2 fields mistakely using the wrong type will crash
with a null pointer derefernce which is much easier to debug
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/jpeg2000.c')
-rw-r--r-- | libavcodec/jpeg2000.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/libavcodec/jpeg2000.c b/libavcodec/jpeg2000.c index bcbb25c806..62b6874a96 100644 --- a/libavcodec/jpeg2000.c +++ b/libavcodec/jpeg2000.c @@ -200,9 +200,17 @@ int ff_jpeg2000_init_component(Jpeg2000Component *comp, csize = (comp->coord[0][1] - comp->coord[0][0]) * (comp->coord[1][1] - comp->coord[1][0]); - comp->data = av_malloc_array(csize, sizeof(*comp->data)); - if (!comp->data) - return AVERROR(ENOMEM); + if (codsty->transform == FF_DWT97) { + comp->i_data = NULL; + comp->f_data = av_malloc_array(csize, sizeof(*comp->f_data)); + if (!comp->f_data) + return AVERROR(ENOMEM); + } else { + comp->f_data = NULL; + comp->i_data = av_malloc_array(csize, sizeof(*comp->i_data)); + if (!comp->i_data) + return AVERROR(ENOMEM); + } comp->reslevel = av_malloc_array(codsty->nreslevels, sizeof(*comp->reslevel)); if (!comp->reslevel) return AVERROR(ENOMEM); @@ -470,5 +478,6 @@ void ff_jpeg2000_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty) ff_dwt_destroy(&comp->dwt); av_freep(&comp->reslevel); - av_freep(&comp->data); + av_freep(&comp->i_data); + av_freep(&comp->f_data); } |