[libbluray-devel] Fix allocs in graphics_controller

hpi1 git at videolan.org
Thu Jul 6 23:23:47 CEST 2017


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Sat Jun 10 14:33:14 2017 +0300| [3be8ac1bec9b5b87b3b6440c33c68831bf636f36] | committer: hpi1

Fix allocs in graphics_controller

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

 src/libbluray/decoders/graphics_controller.c | 24 ++++++------------------
 src/libbluray/decoders/ig.h                  |  2 ++
 2 files changed, 8 insertions(+), 18 deletions(-)

diff --git a/src/libbluray/decoders/graphics_controller.c b/src/libbluray/decoders/graphics_controller.c
index 8e8cf6ea..a53486bd 100644
--- a/src/libbluray/decoders/graphics_controller.c
+++ b/src/libbluray/decoders/graphics_controller.c
@@ -83,7 +83,7 @@ struct graphics_controller_s {
     unsigned        popup_visible;
     unsigned        valid_mouse_position;
     unsigned        auto_action_triggered;
-    BOG_DATA       *bog_data;
+    BOG_DATA        bog_data[MAX_NUM_BOGS];
     BOG_DATA       *saved_bog_data;
     BD_UO_MASK      page_uo_mask;
 
@@ -359,10 +359,6 @@ static void _reset_user_timeout(GRAPHICS_CONTROLLER *gc)
 
 static int _save_page_state(GRAPHICS_CONTROLLER *gc)
 {
-    if (!gc->bog_data) {
-        GC_TRACE("_save_page_state(): no bog data !\n");
-        return -1;
-    }
     if (!gc->igs || !gc->igs->ics) {
         GC_TRACE("_save_page_state(): no IG composition\n");
         return -1;
@@ -383,7 +379,7 @@ static int _save_page_state(GRAPHICS_CONTROLLER *gc)
     /* copy enabled button state, clear draw state */
 
     X_FREE(gc->saved_bog_data);
-    gc->saved_bog_data = calloc(page->num_bogs, sizeof(*gc->saved_bog_data));
+    gc->saved_bog_data = calloc(1, sizeof(gc->bog_data));
     if (!gc->saved_bog_data) {
         GC_ERROR("_save_page_state(): out of memory\n");
         return -1;
@@ -403,13 +399,8 @@ static int _restore_page_state(GRAPHICS_CONTROLLER *gc)
     gc->out_effects = NULL;
 
     if (gc->saved_bog_data) {
-        if (gc->bog_data) {
-            GC_ERROR("_restore_page_state(): bog data already exists !\n");
-            X_FREE(gc->bog_data);
-        }
-        gc->bog_data       = gc->saved_bog_data;
-        gc->saved_bog_data = NULL;
-
+        memcpy(gc->bog_data, gc->saved_bog_data, sizeof(gc->bog_data));
+        X_FREE(gc->saved_bog_data);
         return 1;
     }
     return -1;
@@ -429,10 +420,7 @@ static void _reset_page_state(GRAPHICS_CONTROLLER *gc)
         return;
     }
 
-    size_t size = page->num_bogs * sizeof(*gc->bog_data);
-    gc->bog_data = realloc(gc->bog_data, size);
-
-    memset(gc->bog_data, 0, size);
+    memset(gc->bog_data, 0, sizeof(gc->bog_data));
 
     for (ii = 0; ii < page->num_bogs; ii++) {
         gc->bog_data[ii].enabled_button = page->bog[ii].default_valid_button_id_ref;
@@ -753,7 +741,7 @@ static void _gc_reset(GRAPHICS_CONTROLLER *gc)
     gc->next_dialog_idx = 0;
     gc->textst_user_style = -1;
 
-    X_FREE(gc->bog_data);
+    memset(gc->bog_data, 0, sizeof(gc->bog_data));
 }
 
 /*
diff --git a/src/libbluray/decoders/ig.h b/src/libbluray/decoders/ig.h
index 789e59f9..1abcc647 100644
--- a/src/libbluray/decoders/ig.h
+++ b/src/libbluray/decoders/ig.h
@@ -94,6 +94,8 @@ typedef struct bd_ig_effect_sequence_s {
 
 } BD_IG_EFFECT_SEQUENCE;
 
+#define MAX_NUM_BOGS  256
+
 typedef struct bd_ig_page_s {
     uint8_t       id;
     uint8_t       version;



More information about the libbluray-devel mailing list