[libbluray-devel] [PATCH 3/3] use strdup

Rafaël Carré funman at videolan.org
Mon Jan 2 18:46:10 CET 2012


---
 src/examples/mpls_dump.c         |    4 +---
 src/libbluray/bdnav/meta_parse.c |    3 +--
 src/libbluray/bdnav/navigation.c |    7 ++-----
 src/libbluray/bluray.c           |    3 +--
 4 files changed, 5 insertions(+), 12 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..5339bd9 100644
--- a/src/libbluray/bdnav/meta_parse.c
+++ b/src/libbluray/bdnav/meta_parse.c
@@ -79,8 +79,7 @@ static void _parseManifestNode(xmlNode * a_node, META_DL *disclib)
                     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(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 a9b1b63..1c4990a 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -974,8 +974,7 @@ BLURAY *bd_open(const char* device_path, const char* keyfile_path)
 
     BD_DEBUG(DBG_BLURAY, "libbluray version "BLURAY_VERSION_STRING"\n");
 
-    bd->device_path = (char*)malloc(strlen(device_path) + 1);
-    strcpy(bd->device_path, device_path);
+    bd->device_path = strdup(device_path);
 #ifdef __linux__
     get_mount_point(bd);
 #endif
-- 
1.7.7.3


More information about the libbluray-devel mailing list