Hans Leidekker : msi: Store string length in the record structure.

Alexandre Julliard julliard at winehq.org
Mon Oct 29 13:52:52 CDT 2012


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

Author: Hans Leidekker <hans at codeweavers.com>
Date:   Mon Oct 29 12:13:12 2012 +0100

msi: Store string length in the record structure.

---

 dlls/msi/msipriv.h |    2 ++
 dlls/msi/record.c  |   39 +++++++++++++++++++++++++++------------
 2 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/dlls/msi/msipriv.h b/dlls/msi/msipriv.h
index 4757da4..56c9340 100644
--- a/dlls/msi/msipriv.h
+++ b/dlls/msi/msipriv.h
@@ -118,6 +118,7 @@ typedef struct tagMSIFIELD
         LPWSTR szwVal;
         IStream *stream;
     } u;
+    int len;
 } MSIFIELD;
 
 typedef struct tagMSIRECORD
@@ -821,6 +822,7 @@ extern UINT MSI_RecordCopyField( MSIRECORD *, UINT, MSIRECORD *, UINT ) DECLSPEC
 extern MSIRECORD *MSI_CloneRecord( MSIRECORD * ) DECLSPEC_HIDDEN;
 extern BOOL MSI_RecordsAreEqual( MSIRECORD *, MSIRECORD * ) DECLSPEC_HIDDEN;
 extern BOOL MSI_RecordsAreFieldsEqual(MSIRECORD *a, MSIRECORD *b, UINT field) DECLSPEC_HIDDEN;
+extern UINT msi_record_set_string(MSIRECORD *, UINT, const WCHAR *, int) DECLSPEC_HIDDEN;
 
 /* stream internals */
 extern void enum_stream_names( IStorage *stg ) DECLSPEC_HIDDEN;
diff --git a/dlls/msi/record.c b/dlls/msi/record.c
index 1dace78..3bf1ee5 100644
--- a/dlls/msi/record.c
+++ b/dlls/msi/record.c
@@ -616,32 +616,47 @@ UINT WINAPI MsiRecordSetStringA( MSIHANDLE handle, UINT iField, LPCSTR szValue )
     return ret;
 }
 
-UINT MSI_RecordSetStringW( MSIRECORD *rec, UINT iField, LPCWSTR szValue )
+static WCHAR *msi_strdupW( const WCHAR *value, int len )
 {
-    LPWSTR str;
+    WCHAR *ret;
 
-    TRACE("%p %d %s\n", rec, iField, debugstr_w(szValue));
+    if (!(ret = msi_alloc( (len + 1) * sizeof(WCHAR) ))) return NULL;
+    memcpy( ret, value, len * sizeof(WCHAR) );
+    ret[len] = 0;
+    return ret;
+}
 
-    if( iField > rec->count )
+UINT msi_record_set_string( MSIRECORD *rec, UINT field, const WCHAR *value, int len )
+{
+    if (field > rec->count)
         return ERROR_INVALID_FIELD;
 
-    MSI_FreeField( &rec->fields[iField] );
+    MSI_FreeField( &rec->fields[field] );
 
-    if( szValue && szValue[0] )
+    if (value && len < 0) len = strlenW( value );
+
+    if (value && len)
     {
-        str = strdupW( szValue );
-        rec->fields[iField].type = MSIFIELD_WSTR;
-        rec->fields[iField].u.szwVal = str;
+        rec->fields[field].type = MSIFIELD_WSTR;
+        rec->fields[field].u.szwVal = msi_strdupW( value, len );
+        rec->fields[field].len = len;
     }
     else
     {
-        rec->fields[iField].type = MSIFIELD_NULL;
-        rec->fields[iField].u.szwVal = NULL;
+        rec->fields[field].type = MSIFIELD_NULL;
+        rec->fields[field].u.szwVal = NULL;
+        rec->fields[field].len = 0;
     }
-
     return 0;
 }
 
+UINT MSI_RecordSetStringW( MSIRECORD *rec, UINT iField, LPCWSTR szValue )
+{
+    TRACE("%p %d %s\n", rec, iField, debugstr_w(szValue));
+
+    return msi_record_set_string( rec, iField, szValue, -1 );
+}
+
 UINT WINAPI MsiRecordSetStringW( MSIHANDLE handle, UINT iField, LPCWSTR szValue )
 {
     MSIRECORD *rec;




More information about the wine-cvs mailing list