[libdvdnav-devel] Use calloc instead of malloc, then memset

Steve Dibb git at videolan.org
Wed Jan 21 17:23:12 CET 2015


libdvdread | branch: master | Steve Dibb <steve.dibb at gmail.com> | Thu Jan 15 13:45:37 2015 -0700| [76f813477a863873bea842e4ae182b3c4cacfc96] | committer: Jean-Baptiste Kempf

Use calloc instead of malloc, then memset

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/libdvdread.git/?a=commit;h=76f813477a863873bea842e4ae182b3c4cacfc96
---

 src/ifo_read.c |   15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/src/ifo_read.c b/src/ifo_read.c
index 9789ddf..e19f995 100644
--- a/src/ifo_read.c
+++ b/src/ifo_read.c
@@ -292,12 +292,10 @@ ifo_handle_t *ifoOpen(dvd_reader_t *dvd, int title) {
   int bup_file_opened = 0;
   char ifo_filename[13];
 
-  ifofile = malloc(sizeof(ifo_handle_t));
+  ifofile = calloc(1, sizeof(ifo_handle_t));
   if(!ifofile)
     return NULL;
 
-  memset(ifofile, 0, sizeof(ifo_handle_t));
-
   ifofile->file = DVDOpenFile(dvd, title, DVD_READ_INFO_FILE);
   if(!ifofile->file) { /* Failed to open IFO, try to open BUP */
     ifofile->file = DVDOpenFile(dvd, title, DVD_READ_INFO_BACKUP_FILE);
@@ -359,11 +357,10 @@ ifoOpen_try_bup:
   /* Try BUP instead */
   ifoClose(ifofile);
 
-  ifofile = malloc(sizeof(ifo_handle_t));
+  ifofile = calloc(1, sizeof(ifo_handle_t));
   if(!ifofile)
     return NULL;
 
-  memset(ifofile, 0, sizeof(ifo_handle_t));
   ifofile->file = DVDOpenFile(dvd, title, DVD_READ_INFO_BACKUP_FILE);
 
   if (title)
@@ -425,12 +422,10 @@ ifoOpen_fail:
 ifo_handle_t *ifoOpenVMGI(dvd_reader_t *dvd) {
   ifo_handle_t *ifofile;
 
-  ifofile = malloc(sizeof(ifo_handle_t));
+  ifofile = calloc(1, sizeof(ifo_handle_t));
   if(!ifofile)
     return NULL;
 
-  memset(ifofile, 0, sizeof(ifo_handle_t));
-
   ifofile->file = DVDOpenFile(dvd, 0, DVD_READ_INFO_FILE);
   if(!ifofile->file) /* Should really catch any error and try to fallback */
     ifofile->file = DVDOpenFile(dvd, 0, DVD_READ_INFO_BACKUP_FILE);
@@ -452,12 +447,10 @@ ifo_handle_t *ifoOpenVMGI(dvd_reader_t *dvd) {
 ifo_handle_t *ifoOpenVTSI(dvd_reader_t *dvd, int title) {
   ifo_handle_t *ifofile;
 
-  ifofile = malloc(sizeof(ifo_handle_t));
+  ifofile = calloc(1, sizeof(ifo_handle_t));
   if(!ifofile)
     return NULL;
 
-  memset(ifofile, 0, sizeof(ifo_handle_t));
-
   if(title <= 0 || title > 99) {
     fprintf(stderr, "libdvdread: ifoOpenVTSI invalid title (%d).\n", title);
     free(ifofile);



More information about the libdvdnav-devel mailing list