File matvar_struct.patch of Package matio

From 4636dfab4012b7468ff338e1de2b77db701f4107 Mon Sep 17 00:00:00 2001
From: Christopher Hulbert <chulbe2lsu@users.sourceforge.net>
Date: Wed, 19 Dec 2012 07:46:36 -0500
Subject: [PATCH 1/2] Initialize fields of structure to NULL

* src/matvar_struct.c (Mat_VarCreateStruct): Initialize the pointer to each
      field to NULL after allocation
---
 src/matvar_struct.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/matvar_struct.c b/src/matvar_struct.c
index af23fee..88a2a8a 100644
--- a/src/matvar_struct.c
+++ b/src/matvar_struct.c
@@ -88,8 +88,12 @@ Mat_VarCreateStruct(const char *name,int rank,size_t *dims,const char **fields,
             }
         }
         if ( NULL != matvar && nmemb > 0 && nfields > 0 ) {
+            matvar_t **field_vars;
             matvar->nbytes = nmemb*nfields*matvar->data_size;
             matvar->data = malloc(matvar->nbytes);
+            field_vars = (matvar_t**)matvar->data;
+            for ( i = 0; i < nfields*nmemb; i++ )
+                field_vars[i] = NULL;
         }
     }
 
-- 
1.7.12.2


From 09f5c87438a5883361b38cc98b4848acfcb65d97 Mon Sep 17 00:00:00 2001
From: Christopher Hulbert <chulbe2lsu@users.sourceforge.net>
Date: Wed, 19 Dec 2012 07:48:05 -0500
Subject: [PATCH 2/2] Fix NULL argument test for Mat_VarGetNumberOfFields

* test/test_mat.c (test_struct_api_getfieldnames): Pass NULL rather than
      matvar to Mat_VarGetNumberOfFields when testing behavior of NULL
      argument
---
 test/test_mat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/test_mat.c b/test/test_mat.c
index 8f2b236..fe87f65 100644
--- a/test/test_mat.c
+++ b/test/test_mat.c
@@ -2173,7 +2173,7 @@ test_struct_api_getfieldnames(void)
     }
     Mat_VarFree(matvar);
 
-    nfields     = Mat_VarGetNumberOfFields(matvar);
+    nfields     = Mat_VarGetNumberOfFields(NULL);
     fieldnames2 = Mat_VarGetStructFieldnames(NULL);
     printf("Fieldnames of \"NULL\":\n");
     if ( nfields < 1 ) {
-- 
1.7.12.2
openSUSE Build Service is sponsored by