[libbluray-devel] Avoid arrays with unspecified length

hpi1 git at videolan.org
Sun Sep 23 23:54:13 CEST 2012


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Mon Sep 24 00:13:53 2012 +0300| [5d93ad7940c22fc7dea599a00cfc78f624f15189] | committer: hpi1

Avoid arrays with unspecified length

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=5d93ad7940c22fc7dea599a00cfc78f624f15189
---

 src/libbluray/bdnav/sound_parse.c |    5 ++++-
 src/libbluray/bdnav/sound_parse.h |    2 +-
 src/libbluray/hdmv/mobj_parse.c   |    5 ++++-
 src/libbluray/hdmv/mobj_parse.h   |    2 +-
 4 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/libbluray/bdnav/sound_parse.c b/src/libbluray/bdnav/sound_parse.c
index 160d0b8..22547f2 100644
--- a/src/libbluray/bdnav/sound_parse.c
+++ b/src/libbluray/bdnav/sound_parse.c
@@ -114,6 +114,8 @@ void sound_free(SOUND_DATA **p)
             X_FREE((*p)->sounds[i].samples);
         }
 
+        X_FREE((*p)->sounds);
+
         X_FREE(*p);
     }
 }
@@ -154,8 +156,9 @@ SOUND_DATA *sound_parse(const char *file_name)
     }
 
     data_offsets = calloc(num_sounds, sizeof(uint32_t));
-    data = calloc(1, sizeof(SOUND_DATA) + num_sounds * sizeof(SOUND_OBJECT));
+    data = calloc(1, sizeof(SOUND_DATA));
     data->num_sounds = num_sounds;
+    data->sounds = calloc(num_sounds, sizeof(SOUND_OBJECT));
 
     /* parse headers */
 
diff --git a/src/libbluray/bdnav/sound_parse.h b/src/libbluray/bdnav/sound_parse.h
index 8d36986..84a5b5f 100644
--- a/src/libbluray/bdnav/sound_parse.h
+++ b/src/libbluray/bdnav/sound_parse.h
@@ -35,7 +35,7 @@ typedef struct {
 
 typedef struct {
     uint16_t     num_sounds;
-    SOUND_OBJECT sounds[];
+    SOUND_OBJECT *sounds;
 } SOUND_DATA;
 
 
diff --git a/src/libbluray/hdmv/mobj_parse.c b/src/libbluray/hdmv/mobj_parse.c
index 960ba16..e933210 100644
--- a/src/libbluray/hdmv/mobj_parse.c
+++ b/src/libbluray/hdmv/mobj_parse.c
@@ -106,6 +106,8 @@ void mobj_free(MOBJ_OBJECTS **p)
             X_FREE((*p)->objects[i].cmds);
         }
 
+        X_FREE((*p)->objects);
+
         X_FREE(*p);
     }
 }
@@ -144,8 +146,9 @@ static MOBJ_OBJECTS *_mobj_parse(const char *file_name)
     bs_skip(&bs, 32); /* reserved */
     num_objects = bs_read(&bs, 16);
 
-    objects = calloc(1, sizeof(MOBJ_OBJECTS) + num_objects * sizeof(MOBJ_OBJECT));
+    objects = calloc(1, sizeof(MOBJ_OBJECTS));
     objects->num_objects = num_objects;
+    objects->objects = calloc(num_objects, sizeof(MOBJ_OBJECT));
 
     for (i = 0; i < objects->num_objects; i++) {
         if (!_mobj_parse_object(&bs, &objects->objects[i])) {
diff --git a/src/libbluray/hdmv/mobj_parse.h b/src/libbluray/hdmv/mobj_parse.h
index cd1fb32..52077d3 100644
--- a/src/libbluray/hdmv/mobj_parse.h
+++ b/src/libbluray/hdmv/mobj_parse.h
@@ -58,7 +58,7 @@ typedef struct {
 
 typedef struct {
     uint16_t    num_objects;
-    MOBJ_OBJECT objects[];
+    MOBJ_OBJECT *objects;
 } MOBJ_OBJECTS;
 
 



More information about the libbluray-devel mailing list