[libbluray-devel] use strdup

Rafaël Carré git at videolan.org
Sun Jan 15 20:01:03 CET 2012


libbluray | branch: master | Rafaël Carré <funman at videolan.org> | Mon Jan  2 12:55:18 2012 -0500| [d56846ef8c6a90a6f53a2db697dd4966fa3a0275] | committer: hpi1

use strdup

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

 src/examples/mpls_dump.c         |    4 +---
 src/libbluray/bdnav/meta_parse.c |    4 +---
 src/libbluray/bdnav/navigation.c |    7 ++-----
 src/libbluray/bluray.c           |    3 +--
 4 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/src/examples/mpls_dump.c b/src/examples/mpls_dump.c
index e1206e8..6d0ed51 100644
--- a/src/examples/mpls_dump.c
+++ b/src/examples/mpls_dump.c
@@ -644,9 +644,7 @@ main(int argc, char *argv[])
             int jj = 0;
             for (ent = readdir(dir); ent != NULL; ent = readdir(dir)) {
                 if (ent->d_name != NULL) {
-                    dirlist[jj] = (char*)malloc(strlen(ent->d_name) + 1);
-                    strcpy(dirlist[jj], ent->d_name);
-                    jj++;
+                    dirlist[jj++] = strdup(ent->d_name);
                 }
             }
             qsort(dirlist, jj, sizeof(char*), _qsort_str_cmp);
diff --git a/src/libbluray/bdnav/meta_parse.c b/src/libbluray/bdnav/meta_parse.c
index 86c9a8f..8a75145 100644
--- a/src/libbluray/bdnav/meta_parse.c
+++ b/src/libbluray/bdnav/meta_parse.c
@@ -78,9 +78,7 @@ static void _parseManifestNode(xmlNode * a_node, META_DL *disclib)
                     uint8_t i = disclib->thumb_count;
                     disclib->thumb_count++;
                     disclib->thumbnails = realloc(disclib->thumbnails, (disclib->thumb_count*sizeof(META_THUMBNAIL)));
-                    int len = xmlStrlen(xmlGetProp(cur_node, xmlCharStrdup("href")));
-                    disclib->thumbnails[i].path = (char*) malloc(len+1);
-                    strcpy(disclib->thumbnails[i].path, (char*) xmlGetProp(cur_node, xmlCharStrdup("href")));
+                    disclib->thumbnails[i].path = strdup((const char*)xmlGetProp(cur_node, xmlCharStrdup("href")));
                     if (xmlGetProp(cur_node, xmlCharStrdup("size"))) {
                         sscanf((const char*)xmlGetProp(cur_node, xmlCharStrdup("size")), "%ix%i", &disclib->thumbnails[i].xres, &disclib->thumbnails[i].yres);
                     }
diff --git a/src/libbluray/bdnav/navigation.c b/src/libbluray/bdnav/navigation.c
index bf34590..46e47a7 100644
--- a/src/libbluray/bdnav/navigation.c
+++ b/src/libbluray/bdnav/navigation.c
@@ -277,9 +277,7 @@ char* nav_find_main_title(const char *root)
         mpls_free(pl_list[ii]);
     }
     if (count > 0) {
-        char *str = (char*)malloc(strlen(longest) + 1);
-        strcpy(str, longest);
-        return str;
+        return strdup(longest);
     } else {
         return NULL;
     }
@@ -466,8 +464,7 @@ NAV_TITLE* nav_title_open(const char *root, const char *playlist, unsigned angle
     if (title == NULL) {
         return NULL;
     }
-    title->root = (char*)malloc(strlen(root) + 1);
-    strcpy(title->root, root);
+    title->root = strdup(root);
     strncpy(title->name, playlist, 11);
     title->name[10] = '\0';
     path = str_printf("%s" DIR_SEP "BDMV" DIR_SEP "PLAYLIST" DIR_SEP "%s",
diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index 2df45d2..9645553 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -927,8 +927,7 @@ BLURAY *bd_open(const char* device_path, const char* keyfile_path)
         return NULL;
     }
 
-    bd->device_path = (char*)malloc(strlen(device_path) + 1);
-    strcpy(bd->device_path, device_path);
+    bd->device_path = strdup(device_path);
 
     _libaacs_open(bd, keyfile_path);
 



More information about the libbluray-devel mailing list