shithub: libdvdcss

Download patch

ref: e9a536a00d337e79fde3b69bf5461f8bedda9391
parent: 1ea1dffd2d44956e8bd1ff92bdc2035376fb6272
author: Diego Biurrun <diego@biurrun.de>
date: Thu Feb 14 11:17:42 EST 2013

Replace memset(0) by zero initializations

Signed-off-by: Diego Biurrun <diego@biurrun.de>

--- a/src/device.c
+++ b/src/device.c
@@ -617,9 +617,8 @@
                 (srbDiskInfo.SRB_Int13HDriveInfo == c_drive) )
             {
                 /* Make sure this is a CD-ROM device */
-                struct SRB_GDEVBlock srbGDEVBlock;
+                struct SRB_GDEVBlock srbGDEVBlock = { 0 };
 
-                memset( &srbGDEVBlock, 0, sizeof(struct SRB_GDEVBlock) );
                 srbGDEVBlock.SRB_Cmd    = SC_GET_DEV_TYPE;
                 srbGDEVBlock.SRB_HaId   = i;
                 srbGDEVBlock.SRB_Target = j;
@@ -998,7 +997,7 @@
 static int aspi_read_internal( int i_fd, void *p_data, int i_blocks )
 {
     HANDLE hEvent;
-    struct SRB_ExecSCSICmd ssc;
+    struct SRB_ExecSCSICmd ssc = { 0 };
     struct w32_aspidev *fd = (struct w32_aspidev *) i_fd;
 
     /* Create the transfer completion event */
@@ -1007,8 +1006,6 @@
     {
         return -1;
     }
-
-    memset( &ssc, 0, sizeof( ssc ) );
 
     ssc.SRB_Cmd         = SC_EXEC_SCSI_CMD;
     ssc.SRB_Flags       = SRB_DIR_IN | SRB_EVENT_NOTIFY;
--- a/src/ioctl.c
+++ b/src/ioctl.c
@@ -143,9 +143,8 @@
     int i_ret;
 
 #if defined( HAVE_LINUX_DVD_STRUCT )
-    dvd_struct dvd;
+    dvd_struct dvd = { 0 };
 
-    memset( &dvd, 0, sizeof( dvd ) );
     dvd.type = DVD_STRUCT_COPYRIGHT;
     dvd.copyright.layer_num = i_layer;
 
@@ -154,9 +153,8 @@
     *pi_copyright = dvd.copyright.cpst;
 
 #elif defined( HAVE_BSD_DVD_STRUCT )
-    struct dvd_struct dvd;
+    struct dvd_struct dvd = { 0 };
 
-    memset( &dvd, 0, sizeof( dvd ) );
     dvd.format = DVD_STRUCT_COPYRIGHT;
     dvd.layer_num = i_layer;
 
@@ -280,12 +278,10 @@
     int i_ret;
 
 #if defined( HAVE_LINUX_DVD_STRUCT )
-    dvd_struct dvd;
+    dvd_struct dvd = { 0 };
 
-    memset( &dvd, 0, sizeof( dvd ) );
     dvd.type = DVD_STRUCT_DISCKEY;
     dvd.disckey.agid = *pi_agid;
-    memset( dvd.disckey.value, 0, DVD_DISCKEY_SIZE );
 
     i_ret = ioctl( i_fd, DVD_READ_STRUCT, &dvd );
 
@@ -297,12 +293,10 @@
     memcpy( p_key, dvd.disckey.value, DVD_DISCKEY_SIZE );
 
 #elif defined( HAVE_BSD_DVD_STRUCT )
-    struct dvd_struct dvd;
+    struct dvd_struct dvd = { 0 };
 
-    memset( &dvd, 0, sizeof( dvd ) );
     dvd.format = DVD_STRUCT_DISCKEY;
     dvd.agid = *pi_agid;
-    memset( dvd.data, 0, DVD_DISCKEY_SIZE );
 
     i_ret = ioctl( i_fd, DVDIOCREADSTRUCTURE, &dvd );
 
@@ -373,11 +367,9 @@
     if( WIN2K ) /* NT/2k/XP */
     {
         DWORD tmp;
-        uint8_t buffer[DVD_DISK_KEY_LENGTH];
+        uint8_t buffer[DVD_DISK_KEY_LENGTH] = { 0 };
         PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
 
-        memset( &buffer, 0, sizeof( buffer ) );
-
         key->KeyLength  = DVD_DISK_KEY_LENGTH;
         key->SessionId  = *pi_agid;
         key->KeyType    = DvdDiskKey;
@@ -453,9 +445,8 @@
     int i_ret;
 
 #if defined( HAVE_LINUX_DVD_STRUCT )
-    dvd_authinfo auth_info;
+    dvd_authinfo auth_info = { 0 };
 
-    memset( &auth_info, 0, sizeof( auth_info ) );
     auth_info.type = DVD_LU_SEND_TITLE_KEY;
     auth_info.lstk.agid = *pi_agid;
     auth_info.lstk.lba = i_pos;
@@ -465,9 +456,8 @@
     memcpy( p_key, auth_info.lstk.title_key, DVD_KEY_SIZE );
 
 #elif defined( HAVE_BSD_DVD_STRUCT )
-    struct dvd_authinfo auth_info;
+    struct dvd_authinfo auth_info = { 0 };
 
-    memset( &auth_info, 0, sizeof( auth_info ) );
     auth_info.format = DVD_REPORT_TITLE_KEY;
     auth_info.agid = *pi_agid;
     auth_info.lba = i_pos;
@@ -541,11 +531,9 @@
     if( WIN2K ) /* NT/2k/XP */
     {
         DWORD tmp;
-        uint8_t buffer[DVD_TITLE_KEY_LENGTH];
+        uint8_t buffer[DVD_TITLE_KEY_LENGTH] = { 0 };
         PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
 
-        memset( &buffer, 0, sizeof( buffer ) );
-
         key->KeyLength  = DVD_TITLE_KEY_LENGTH;
         key->SessionId  = *pi_agid;
         key->KeyType    = DvdTitleKey;
@@ -619,9 +607,8 @@
     int i_ret;
 
 #if defined( HAVE_LINUX_DVD_STRUCT )
-    dvd_authinfo auth_info;
+    dvd_authinfo auth_info = { 0 };
 
-    memset( &auth_info, 0, sizeof( auth_info ) );
     auth_info.type = DVD_LU_SEND_AGID;
     auth_info.lsa.agid = *pi_agid;
 
@@ -630,9 +617,8 @@
     *pi_agid = auth_info.lsa.agid;
 
 #elif defined( HAVE_BSD_DVD_STRUCT )
-    struct dvd_authinfo auth_info;
+    struct dvd_authinfo auth_info = { 0 };
 
-    memset( &auth_info, 0, sizeof( auth_info ) );
     auth_info.format = DVD_REPORT_AGID;
     auth_info.agid = *pi_agid;
 
@@ -741,9 +727,8 @@
     int i_ret;
 
 #if defined( HAVE_LINUX_DVD_STRUCT )
-    dvd_authinfo auth_info;
+    dvd_authinfo auth_info = { 0 };
 
-    memset( &auth_info, 0, sizeof( auth_info ) );
     auth_info.type = DVD_LU_SEND_CHALLENGE;
     auth_info.lsc.agid = *pi_agid;
 
@@ -752,9 +737,8 @@
     memcpy( p_challenge, auth_info.lsc.chal, DVD_CHALLENGE_SIZE );
 
 #elif defined( HAVE_BSD_DVD_STRUCT )
-    struct dvd_authinfo auth_info;
+    struct dvd_authinfo auth_info =  { 0 };
 
-    memset( &auth_info, 0, sizeof( auth_info ) );
     auth_info.format = DVD_REPORT_CHALLENGE;
     auth_info.agid = *pi_agid;
 
@@ -808,11 +792,9 @@
     if( WIN2K ) /* NT/2k/XP */
     {
         DWORD tmp;
-        uint8_t buffer[DVD_CHALLENGE_KEY_LENGTH];
+        uint8_t buffer[DVD_CHALLENGE_KEY_LENGTH] = { 0 };
         PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
 
-        memset( &buffer, 0, sizeof( buffer ) );
-
         key->KeyLength  = DVD_CHALLENGE_KEY_LENGTH;
         key->SessionId  = *pi_agid;
         key->KeyType    = DvdChallengeKey;
@@ -875,9 +857,8 @@
     int i_ret;
 
 #if defined( HAVE_LINUX_DVD_STRUCT )
-    dvd_authinfo auth_info;
+    dvd_authinfo auth_info = { 0 };
 
-    memset( &auth_info, 0, sizeof( auth_info ) );
     auth_info.type = DVD_LU_SEND_ASF;
     auth_info.lsasf.asf = *pi_asf;
 
@@ -886,9 +867,8 @@
     *pi_asf = auth_info.lsasf.asf;
 
 #elif defined( HAVE_BSD_DVD_STRUCT )
-    struct dvd_authinfo auth_info;
+    struct dvd_authinfo auth_info =  { 0 };
 
-    memset( &auth_info, 0, sizeof( auth_info ) );
     auth_info.format = DVD_REPORT_ASF;
     auth_info.asf = *pi_asf;
 
@@ -940,11 +920,9 @@
     if( WIN2K ) /* NT/2k/XP */
     {
         DWORD tmp;
-        uint8_t buffer[DVD_ASF_LENGTH];
+        uint8_t buffer[DVD_ASF_LENGTH] = { 0 };
         PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
 
-        memset( &buffer, 0, sizeof( buffer ) );
-
         key->KeyLength  = DVD_ASF_LENGTH;
         key->KeyType    = DvdAsf;
         key->KeyFlags   = 0;
@@ -1008,9 +986,8 @@
     int i_ret;
 
 #if defined( HAVE_LINUX_DVD_STRUCT )
-    dvd_authinfo auth_info;
+    dvd_authinfo auth_info = { 0 };
 
-    memset( &auth_info, 0, sizeof( auth_info ) );
     auth_info.type = DVD_LU_SEND_KEY1;
     auth_info.lsk.agid = *pi_agid;
 
@@ -1019,9 +996,8 @@
     memcpy( p_key, auth_info.lsk.key, DVD_KEY_SIZE );
 
 #elif defined( HAVE_BSD_DVD_STRUCT )
-    struct dvd_authinfo auth_info;
+    struct dvd_authinfo auth_info = { 0 };
 
-    memset( &auth_info, 0, sizeof( auth_info ) );
     auth_info.format = DVD_REPORT_KEY1;
     auth_info.agid = *pi_agid;
 
@@ -1075,11 +1051,9 @@
     if( WIN2K ) /* NT/2k/XP */
     {
         DWORD tmp;
-        uint8_t buffer[DVD_BUS_KEY_LENGTH];
+        uint8_t buffer[DVD_BUS_KEY_LENGTH] = { 0 };
         PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
 
-        memset( &buffer, 0, sizeof( buffer ) );
-
         key->KeyLength  = DVD_BUS_KEY_LENGTH;
         key->SessionId  = *pi_agid;
         key->KeyType    = DvdBusKey1;
@@ -1137,9 +1111,8 @@
     int i_ret;
 
 #if defined( HAVE_LINUX_DVD_STRUCT )
-    dvd_authinfo auth_info;
+    dvd_authinfo auth_info = { 0 };
 
-    memset( &auth_info, 0, sizeof( auth_info ) );
     auth_info.type = DVD_INVALIDATE_AGID;
     auth_info.lsa.agid = *pi_agid;
 
@@ -1146,9 +1119,8 @@
     i_ret = ioctl( i_fd, DVD_AUTH, &auth_info );
 
 #elif defined( HAVE_BSD_DVD_STRUCT )
-    struct dvd_authinfo auth_info;
+    struct dvd_authinfo auth_info = { 0 };
 
-    memset( &auth_info, 0, sizeof( auth_info ) );
     auth_info.format = DVD_INVALIDATE_AGID;
     auth_info.agid = *pi_agid;
 
@@ -1248,9 +1220,8 @@
     int i_ret;
 
 #if defined( HAVE_LINUX_DVD_STRUCT )
-    dvd_authinfo auth_info;
+    dvd_authinfo auth_info = { 0 };
 
-    memset( &auth_info, 0, sizeof( auth_info ) );
     auth_info.type = DVD_HOST_SEND_CHALLENGE;
     auth_info.hsc.agid = *pi_agid;
 
@@ -1259,9 +1230,8 @@
     i_ret = ioctl( i_fd, DVD_AUTH, &auth_info );
 
 #elif defined( HAVE_BSD_DVD_STRUCT )
-    struct dvd_authinfo auth_info;
+    struct dvd_authinfo auth_info = { 0 };
 
-    memset( &auth_info, 0, sizeof( auth_info ) );
     auth_info.format = DVD_SEND_CHALLENGE;
     auth_info.agid = *pi_agid;
 
@@ -1320,11 +1290,9 @@
     if( WIN2K ) /* NT/2k/XP */
     {
         DWORD tmp;
-        uint8_t buffer[DVD_CHALLENGE_KEY_LENGTH];
+        uint8_t buffer[DVD_CHALLENGE_KEY_LENGTH] = { 0 };
         PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
 
-        memset( &buffer, 0, sizeof( buffer ) );
-
         key->KeyLength  = DVD_CHALLENGE_KEY_LENGTH;
         key->SessionId  = *pi_agid;
         key->KeyType    = DvdChallengeKey;
@@ -1385,9 +1353,8 @@
     int i_ret;
 
 #if defined( HAVE_LINUX_DVD_STRUCT )
-    dvd_authinfo auth_info;
+    dvd_authinfo auth_info = { 0 };
 
-    memset( &auth_info, 0, sizeof( auth_info ) );
     auth_info.type = DVD_HOST_SEND_KEY2;
     auth_info.hsk.agid = *pi_agid;
 
@@ -1396,9 +1363,8 @@
     i_ret = ioctl( i_fd, DVD_AUTH, &auth_info );
 
 #elif defined( HAVE_BSD_DVD_STRUCT )
-    struct dvd_authinfo auth_info;
+    struct dvd_authinfo auth_info = { 0 };
 
-    memset( &auth_info, 0, sizeof( auth_info ) );
     auth_info.format = DVD_SEND_KEY2;
     auth_info.agid = *pi_agid;
 
@@ -1457,11 +1423,9 @@
     if( WIN2K ) /* NT/2k/XP */
     {
         DWORD tmp;
-        uint8_t buffer[DVD_BUS_KEY_LENGTH];
+        uint8_t buffer[DVD_BUS_KEY_LENGTH] = { 0 };
         PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
 
-        memset( &buffer, 0, sizeof( buffer ) );
-
         key->KeyLength  = DVD_BUS_KEY_LENGTH;
         key->SessionId  = *pi_agid;
         key->KeyType    = DvdBusKey2;
@@ -1522,9 +1486,8 @@
     int i_ret;
 
 #if defined( HAVE_LINUX_DVD_STRUCT ) && defined( DVD_LU_SEND_RPC_STATE )
-    dvd_authinfo auth_info;
+    dvd_authinfo auth_info = { 0 };
 
-    memset( &auth_info, 0, sizeof( auth_info ) );
     auth_info.type = DVD_LU_SEND_RPC_STATE;
 
     i_ret = ioctl( i_fd, DVD_AUTH, &auth_info );
@@ -1538,9 +1501,8 @@
     i_ret = -1;
 
 #elif defined( HAVE_BSD_DVD_STRUCT )
-    struct dvd_authinfo auth_info;
+    struct dvd_authinfo auth_info = { 0 };
 
-    memset( &auth_info, 0, sizeof( auth_info ) );
     auth_info.format = DVD_REPORT_RPC;
 
     i_ret = ioctl( i_fd, DVDIOCREPORTKEY, &auth_info );
@@ -1603,10 +1565,8 @@
     if( WIN2K ) /* NT/2k/XP */
     {
         DWORD tmp;
-        uint8_t buffer[DVD_RPC_KEY_LENGTH];
+        uint8_t buffer[DVD_RPC_KEY_LENGTH] = { 0 };
         PDVD_COPY_PROTECT_KEY key = (PDVD_COPY_PROTECT_KEY) &buffer;
-
-        memset( &buffer, 0, sizeof( buffer ) );
 
         key->KeyLength  = DVD_RPC_KEY_LENGTH;
         key->KeyType    = DvdGetRpcKey;
--- a/src/ioctl.h
+++ b/src/ioctl.h
@@ -44,9 +44,8 @@
  *****************************************************************************/
 #if defined( __BEOS__ )
 #define INIT_RDC( TYPE, SIZE ) \
-    raw_device_command rdc; \
+    raw_device_command rdc = { 0 }; \
     uint8_t p_buffer[ (SIZE)+1 ]; \
-    memset( &rdc, 0, sizeof( raw_device_command ) ); \
     rdc.data = (char *)p_buffer; \
     rdc.data_length = (SIZE); \
     BeInitRDC( &rdc, (TYPE) );
@@ -57,9 +56,8 @@
  *****************************************************************************/
 #if defined( HPUX_SCTL_IO )
 #define INIT_SCTL_IO( TYPE, SIZE ) \
-    struct sctl_io sctl_io; \
+    struct sctl_io sctl_io = { 0 }; \
     uint8_t p_buffer[ (SIZE)+1 ]; \
-    memset( &sctl_io, 0, sizeof( sctl_io ) ); \
     sctl_io.data = (void *)p_buffer; \
     sctl_io.data_length = (SIZE); \
     HPUXInitSCTL( &sctl_io, (TYPE) );
@@ -72,10 +70,9 @@
 #define USCSI_TIMEOUT( SC, TO ) ( (SC)->uscsi_timeout = (TO) )
 #define USCSI_RESID( SC )       ( (SC)->uscsi_resid )
 #define INIT_USCSI( TYPE, SIZE ) \
-    struct uscsi_cmd sc; \
+    struct uscsi_cmd sc = { 0 }; \
     union scsi_cdb rs_cdb; \
     uint8_t p_buffer[ (SIZE)+1 ]; \
-    memset( &sc, 0, sizeof( struct uscsi_cmd ) ); \
     sc.uscsi_cdb = (caddr_t)&rs_cdb; \
     sc.uscsi_bufaddr = (caddr_t)p_buffer; \
     sc.uscsi_buflen = (SIZE); \
@@ -87,10 +84,8 @@
  *****************************************************************************/
 #if defined( DARWIN_DVD_IOCTL )
 #define INIT_DVDIOCTL( DKDVD_TYPE, BUFFER_TYPE, FORMAT ) \
-    DKDVD_TYPE dvd; \
-    BUFFER_TYPE dvdbs; \
-    memset( &dvd, 0, sizeof(dvd) ); \
-    memset( &dvdbs, 0, sizeof(dvdbs) ); \
+    DKDVD_TYPE dvd = { 0 }; \
+    BUFFER_TYPE dvdbs = { 0 }; \
     dvd.format = FORMAT; \
     dvd.buffer = &dvdbs; \
     dvd.bufferLength = sizeof(dvdbs);
@@ -102,9 +97,8 @@
 #if defined( WIN32 )
 #define INIT_SPTD( TYPE, SIZE ) \
     DWORD tmp; \
-    SCSI_PASS_THROUGH_DIRECT sptd; \
+    SCSI_PASS_THROUGH_DIRECT sptd = { 0 }; \
     uint8_t p_buffer[ (SIZE) ]; \
-    memset( &sptd, 0, sizeof( SCSI_PASS_THROUGH_DIRECT ) ); \
     sptd.Length = sizeof( SCSI_PASS_THROUGH_DIRECT ); \
     sptd.DataBuffer = p_buffer; \
     sptd.DataTransferLength = (SIZE); \
@@ -115,9 +109,8 @@
                       (SPTD), sizeof( SCSI_PASS_THROUGH_DIRECT ), \
                       (TMP), NULL ) ? 0 : -1)
 #define INIT_SSC( TYPE, SIZE ) \
-    struct SRB_ExecSCSICmd ssc; \
+    struct SRB_ExecSCSICmd ssc = { 0 }; \
     uint8_t p_buffer[ (SIZE)+1 ]; \
-    memset( &ssc, 0, sizeof( struct SRB_ExecSCSICmd ) ); \
     ssc.SRB_BufPointer = (unsigned char *)p_buffer; \
     ssc.SRB_BufLen = (SIZE); \
     WinInitSSC( &ssc, (TYPE) );
@@ -128,12 +121,11 @@
  *****************************************************************************/
 #if defined( __QNXNTO__ )
 #define INIT_CPT( TYPE, SIZE ) \
-    CAM_PASS_THRU * p_cpt; \
+    CAM_PASS_THRU * p_cpt = { 0 }; \
     uint8_t * p_buffer; \
     int structSize = sizeof( CAM_PASS_THRU ) + (SIZE); \
     p_cpt = (CAM_PASS_THRU *) malloc ( structSize ); \
     p_buffer = (uint8_t *) p_cpt + sizeof( CAM_PASS_THRU ); \
-    memset( p_cpt, 0, structSize ); \
       p_cpt->cam_data_ptr = sizeof( CAM_PASS_THRU ); \
       p_cpt->cam_dxfer_len = (SIZE); \
     QNXInitCPT( p_cpt, (TYPE) );
@@ -144,12 +136,10 @@
  *****************************************************************************/
 #if defined( __OS2__ )
 #define INIT_SSC( TYPE, SIZE ) \
-    struct OS2_ExecSCSICmd sdc; \
-    uint8_t p_buffer[ (SIZE)+1 ]; \
+    struct OS2_ExecSCSICmd sdc = { 0 }; \
+    uint8_t p_buffer[ (SIZE) + 1 ] = { 0 }; \
     unsigned long ulParamLen; \
     unsigned long ulDataLen; \
-    memset( &sdc, 0, sizeof( OS2_ExecSCSICmd ) ); \
-    memset( &p_buffer, 0, SIZE ); \
     sdc.data_length = (SIZE); \
     ulParamLen = sizeof(sdc); \
     OS2InitSDC( &sdc, (TYPE) )
--- a/test/dvd_region.c
+++ b/test/dvd_region.c
@@ -32,9 +32,8 @@
     int i_ret;
 
 #if defined( HAVE_LINUX_DVD_STRUCT ) && defined( DVD_HOST_SEND_RPC_STATE )
-    dvd_authinfo auth_info;
+    dvd_authinfo auth_info = { 0 };
 
-    memset( &auth_info, 0, sizeof( auth_info ) );
     auth_info.type = DVD_HOST_SEND_RPC_STATE;
     auth_info.hrpcs.pdrc = i_pdrc;
 
@@ -45,9 +44,8 @@
     i_ret = -1;
 
 #elif defined( HAVE_BSD_DVD_STRUCT )
-    struct dvd_authinfo auth_info;
+    struct dvd_authinfo auth_info = { 0 };
 
-    memset( &auth_info, 0, sizeof( auth_info ) );
     auth_info.format = DVD_SEND_RPC;
     auth_info.region = i_pdrc;