[libdvdnav-devel] Check for malloc fail before setting buffer

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


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

Check for malloc fail before setting buffer

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

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

 src/dvd_reader.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/dvd_reader.c b/src/dvd_reader.c
index e22412a..72dc54a 100644
--- a/src/dvd_reader.c
+++ b/src/dvd_reader.c
@@ -1393,7 +1393,6 @@ int DVDDiscID( dvd_reader_t *dvd, unsigned char *discid )
       ssize_t bytes_read;
       ssize_t file_size = dvd_file->filesize * DVD_VIDEO_LB_LEN;
       char *buffer_base = malloc( file_size + 2048 );
-      char *buffer = (char *)(((uintptr_t)buffer_base & ~((uintptr_t)2047)) + 2048);
 
       if( buffer_base == NULL ) {
           DVDCloseFile( dvd_file );
@@ -1402,6 +1401,8 @@ int DVDDiscID( dvd_reader_t *dvd, unsigned char *discid )
           return -1;
       }
 
+      char *buffer = (char *)(((uintptr_t)buffer_base & ~((uintptr_t)2047)) + 2048);
+
       bytes_read = DVDReadBytes( dvd_file, buffer, file_size );
       if( bytes_read != file_size ) {
           fprintf( stderr, "libdvdread: DVDDiscId read returned %zd bytes"



More information about the libdvdnav-devel mailing list