Re: [PATCH v2 4/5] msi: Don't reimplement record formatting.
On Sun, 2017-06-18 at 21:53 -0500, Zebediah Figura wrote:
diff --git a/dlls/msi/package.c b/dlls/msi/package.c index eae01e0..f16b1dc 100644 --- a/dlls/msi/package.c +++ b/dlls/msi/package.c @@ -1709,8 +1709,8 @@ INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType, MSIREC static const WCHAR szSetProgress[] = {'S','e','t','P','r','o','g','r','e','s','s',0}; static const WCHAR szActionText[] = {'A','c','t','i','o','n','T','e','x','t',0}; MSIRECORD *uirow; - LPWSTR deformated, message; - DWORD i, len, total_len, log_type = 0; + LPWSTR deformated, message = {0}; + DWORD len, log_type = 0; INT rc = 0; char *msg;
@@ -1776,39 +1776,10 @@ INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType, MSIREC } else { - static const WCHAR format[] = {'%','u',':',' ',0}; - UINT count = MSI_RecordGetFieldCount( record ); - WCHAR *p; - - total_len = 1; - for (i = 1; i <= count; i++) - { - len = 0; - MSI_RecordGetStringW( record, i, NULL, &len ); - total_len += len + 13; - } - p = message = msi_alloc( total_len * sizeof(WCHAR) ); - if (!p) return ERROR_OUTOFMEMORY; - - for (i = 1; i <= count; i++) - { - if (count > 1) - { - len = sprintfW( p, format, i ); - total_len -= len; - p += len; - } - len = total_len; - MSI_RecordGetStringW( record, i, p, &len ); - total_len -= len; - p += len; - if (count > 1 && total_len) - { - *p++ = ' '; - total_len--; - } - } - p[0] = 0; + MSI_FormatRecordW(package, record, message, &len); + len++; + message = msi_alloc(len * sizeof(WCHAR)); + MSI_FormatRecordW(package, record, message, &len);
You can pass a NULL buffer in the size query. Please keep the check for allocation failure. I would check the first call to MSI_FormatRecordW too since the record is passed by the caller.
On 06/19/2017 04:45 AM, Hans Leidekker wrote:
On Sun, 2017-06-18 at 21:53 -0500, Zebediah Figura wrote:
diff --git a/dlls/msi/package.c b/dlls/msi/package.c index eae01e0..f16b1dc 100644 --- a/dlls/msi/package.c +++ b/dlls/msi/package.c @@ -1709,8 +1709,8 @@ INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType, MSIREC static const WCHAR szSetProgress[] = {'S','e','t','P','r','o','g','r','e','s','s',0}; static const WCHAR szActionText[] = {'A','c','t','i','o','n','T','e','x','t',0}; MSIRECORD *uirow; - LPWSTR deformated, message; - DWORD i, len, total_len, log_type = 0; + LPWSTR deformated, message = {0}; + DWORD len, log_type = 0; INT rc = 0; char *msg;
@@ -1776,39 +1776,10 @@ INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType, MSIREC } else { - static const WCHAR format[] = {'%','u',':',' ',0}; - UINT count = MSI_RecordGetFieldCount( record ); - WCHAR *p; - - total_len = 1; - for (i = 1; i <= count; i++) - { - len = 0; - MSI_RecordGetStringW( record, i, NULL, &len ); - total_len += len + 13; - } - p = message = msi_alloc( total_len * sizeof(WCHAR) ); - if (!p) return ERROR_OUTOFMEMORY; - - for (i = 1; i <= count; i++) - { - if (count > 1) - { - len = sprintfW( p, format, i ); - total_len -= len; - p += len; - } - len = total_len; - MSI_RecordGetStringW( record, i, p, &len ); - total_len -= len; - p += len; - if (count > 1 && total_len) - { - *p++ = ' '; - total_len--; - } - } - p[0] = 0; + MSI_FormatRecordW(package, record, message, &len); + len++; + message = msi_alloc(len * sizeof(WCHAR)); + MSI_FormatRecordW(package, record, message, &len);
You can pass a NULL buffer in the size query. Please keep the check for allocation failure. I would check the first call to MSI_FormatRecordW too since the record is passed by the caller.
I'll send an updated patch.
participants (2)
-
Hans Leidekker -
Zebediah Figura