Michael Stefaniuc : msi: Use FIELD_OFFSET for the size of structs with a varlength array.

Alexandre Julliard julliard at winehq.org
Thu Dec 13 14:22:48 CST 2012


Module: wine
Branch: master
Commit: 62029ff586262ecdfee77d6be9750e8139c79e72
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=62029ff586262ecdfee77d6be9750e8139c79e72

Author: Michael Stefaniuc <mstefani at redhat.de>
Date:   Thu Dec 13 16:56:42 2012 +0100

msi: Use FIELD_OFFSET for the size of structs with a varlength array.

---

 dlls/msi/dialog.c |    4 ++--
 dlls/msi/record.c |    5 ++---
 dlls/msi/where.c  |    2 +-
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/dlls/msi/dialog.c b/dlls/msi/dialog.c
index c0ff204..a983106 100644
--- a/dlls/msi/dialog.c
+++ b/dlls/msi/dialog.c
@@ -1135,7 +1135,7 @@ static UINT msi_dialog_line_control( msi_dialog *dialog, MSIRECORD *rec )
 
     msi_dialog_map_events(dialog, name);
 
-    control = msi_alloc( sizeof(*control) + strlenW(name) * sizeof(WCHAR) );
+    control = msi_alloc( FIELD_OFFSET(msi_control, name[strlenW( name ) + 1] ));
     if (!control)
         return ERROR_OUTOFMEMORY;
 
@@ -3735,7 +3735,7 @@ msi_dialog *msi_dialog_create( MSIPACKAGE* package,
         msi_dialog_register_class();
 
     /* allocate the structure for the dialog to use */
-    dialog = msi_alloc_zero( sizeof *dialog + sizeof(WCHAR)*strlenW(szDialogName) );
+    dialog = msi_alloc_zero( FIELD_OFFSET( msi_dialog, name[strlenW( szDialogName ) + 1] ));
     if( !dialog )
         return NULL;
     strcpyW( dialog->name, szDialogName );
diff --git a/dlls/msi/record.c b/dlls/msi/record.c
index dd097ea..a44f42d 100644
--- a/dlls/msi/record.c
+++ b/dlls/msi/record.c
@@ -79,15 +79,14 @@ void MSI_CloseRecord( MSIOBJECTHDR *arg )
 MSIRECORD *MSI_CreateRecord( UINT cParams )
 {
     MSIRECORD *rec;
-    UINT len;
 
     TRACE("%d\n", cParams);
 
     if( cParams>65535 )
         return NULL;
 
-    len = sizeof (MSIRECORD) + sizeof (MSIFIELD)*cParams;
-    rec = alloc_msiobject( MSIHANDLETYPE_RECORD, len, MSI_CloseRecord );
+    rec = alloc_msiobject( MSIHANDLETYPE_RECORD, FIELD_OFFSET(MSIRECORD, fields[cParams + 1]),
+            MSI_CloseRecord );
     if( rec )
         rec->count = cParams;
     return rec;
diff --git a/dlls/msi/where.c b/dlls/msi/where.c
index 1bf7788..10c4b37 100644
--- a/dlls/msi/where.c
+++ b/dlls/msi/where.c
@@ -1068,7 +1068,7 @@ static UINT WHERE_sort(struct tagMSIVIEW *view, column_info *columns)
     if (count == 0)
         return ERROR_SUCCESS;
 
-    orderinfo = msi_alloc(sizeof(MSIORDERINFO) + (count - 1) * sizeof(union ext_column));
+    orderinfo = msi_alloc(FIELD_OFFSET(MSIORDERINFO, columns[count]));
     if (!orderinfo)
         return ERROR_OUTOFMEMORY;
 




More information about the wine-cvs mailing list