[libbluray-devel] Changed disc_read_file method's return type to size_t

tourettes git at videolan.org
Sun Feb 15 22:45:57 CET 2015


libbluray | branch: master | tourettes <tourettes at team-mediaportal.com> | Sun Feb 15 18:06:42 2015 +0200| [72dc0db233cfbb6c3e318280fbb846e0f2107ead] | committer: hpi1

Changed disc_read_file method's return type to size_t

Failed read is indicated with zero return value

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

 src/libbluray/bdnav/meta_parse.c |    4 ++--
 src/libbluray/bluray.c           |    4 ++--
 src/libbluray/disc/disc.c        |   17 ++++++++++-------
 src/libbluray/disc/disc.h        |    2 +-
 4 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/src/libbluray/bdnav/meta_parse.c b/src/libbluray/bdnav/meta_parse.c
index d0d3c69..50b8c75 100644
--- a/src/libbluray/bdnav/meta_parse.c
+++ b/src/libbluray/bdnav/meta_parse.c
@@ -153,11 +153,11 @@ META_ROOT *meta_parse(BD_DISC *disc)
     uint8_t i;
     for (i = 0; i < root->dl_count; i++) {
         uint8_t *data = NULL;
-        int64_t size = 0;
+        size_t size;
         size = disc_read_file(disc, "BDMV" DIR_SEP "META" DIR_SEP "DL",
                               root->dl_entries[i].filename,
                               &data);
-        if (!data) {
+        if (!data || size == 0) {
             BD_DEBUG(DBG_DIR, "Failed to read BDMV/META/DL/%s\n", root->dl_entries[i].filename);
         } else {
                 doc = xmlReadMemory((char*)data, (int)size, NULL, NULL, 0);
diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index e1cfbc6..4f950a2 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -1934,8 +1934,8 @@ static int _preload_textst_subpath(BLURAY *bd)
     for (ii = 0; ii < bd->st_textst.clip->cl->font_info.font_count; ii++) {
         char *file = str_printf("%s.otf", bd->st_textst.clip->cl->font_info.font[ii].file_id);
         uint8_t *data = NULL;
-        int64_t size = disc_read_file(bd->disc, "BDMV" DIR_SEP "AUXDATA", file, &data);
-        if (data && gc_add_font(bd->graphics_controller, data, size) < 0) {
+        size_t size = disc_read_file(bd->disc, "BDMV" DIR_SEP "AUXDATA", file, &data);
+        if (data && size > 0 && gc_add_font(bd->graphics_controller, data, size) < 0) {
             X_FREE(data);
         }
         X_FREE(file);
diff --git a/src/libbluray/disc/disc.c b/src/libbluray/disc/disc.c
index c26ee8a..1de00b1 100644
--- a/src/libbluray/disc/disc.c
+++ b/src/libbluray/disc/disc.c
@@ -350,7 +350,7 @@ BD_DIR_H *disc_open_dir(BD_DISC *p, const char *dir)
     return _combine_dirs(dp_ovl, dp_rom);
 }
 
-int64_t disc_read_file(BD_DISC *disc, const char *dir, const char *file,
+size_t disc_read_file(BD_DISC *disc, const char *dir, const char *file,
                        uint8_t **data)
 {
     BD_FILE_H *fp;
@@ -360,26 +360,29 @@ int64_t disc_read_file(BD_DISC *disc, const char *dir, const char *file,
 
     fp = disc_open_file(disc, dir, file);
     if (!fp) {
-        return -1;
+        return 0;
     }
 
     size = file_size(fp);
-    if (size > 0) {
-        *data = malloc(size);
+    if (size > 0 && size < BD_MAX_SSIZE) {
+        *data = malloc((size_t)size);
         if (*data) {
             int64_t got = file_read(fp, *data, size);
             if (got != size) {
                 BD_DEBUG(DBG_FILE | DBG_CRIT, "Error reading file %s from %s\n", file, dir);
                 X_FREE(*data);
-                size = -1;
+                size = 0;
             }
         } else {
-          size = -1;
+          size = 0;
         }
     }
+    else {
+      size = 0;
+    }
 
     file_close(fp);
-    return size;
+    return (size_t)size;
 }
 
 /*
diff --git a/src/libbluray/disc/disc.h b/src/libbluray/disc/disc.h
index 6ce8603..3e20c43 100644
--- a/src/libbluray/disc/disc.h
+++ b/src/libbluray/disc/disc.h
@@ -57,7 +57,7 @@ BD_PRIVATE struct bd_file_s *disc_open_path(BD_DISC *disc, const char *path);
 BD_PRIVATE struct bd_dir_s *disc_open_dir (BD_DISC *disc, const char *dir);
 
 /* Read VFS file */
-BD_PRIVATE int64_t disc_read_file(BD_DISC *disc, const char *dir, const char *file,
+BD_PRIVATE size_t disc_read_file(BD_DISC *disc, const char *dir, const char *file,
                                   uint8_t **data);
 
 /* Update virtual package */



More information about the libbluray-devel mailing list