From 9aa23c6c77766558093df4e28e6070ccfdea236b Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Mon, 29 Oct 2012 12:13:12 +0100 Subject: [PATCH] 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 4757da4d31..56c9340b6a 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 1dace78790..3bf1ee5b5a 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;