Zebediah Figura : msi: Avoid using awstring in MsiGetPropertyA/W().
Alexandre Julliard
julliard at winehq.org
Wed May 16 17:30:27 CDT 2018
Module: wine
Branch: master
Commit: 389ad808d2ac1a443d4a4190928e665b25214c1a
URL: https://source.winehq.org/git/wine.git/?a=commit;h=389ad808d2ac1a443d4a4190928e665b25214c1a
Author: Zebediah Figura <z.figura12 at gmail.com>
Date: Tue May 15 23:03:36 2018 -0500
msi: Avoid using awstring in MsiGetPropertyA/W().
Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
Signed-off-by: Hans Leidekker <hans at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/msi/package.c | 109 ++++++++++++++++++++----------------------------
dlls/msi/tests/custom.c | 6 +++
2 files changed, 51 insertions(+), 64 deletions(-)
diff --git a/dlls/msi/package.c b/dlls/msi/package.c
index 133bfd8..ab6c3dd 100644
--- a/dlls/msi/package.c
+++ b/dlls/msi/package.c
@@ -2345,84 +2345,76 @@ int msi_get_property_int( MSIDATABASE *db, LPCWSTR prop, int def )
return val;
}
-static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
- awstring *szValueBuf, LPDWORD pchValueBuf )
+UINT WINAPI MsiGetPropertyA(MSIHANDLE hinst, const char *name, char *buf, DWORD *sz)
{
+ const WCHAR *value = szEmpty;
MSIPACKAGE *package;
- MSIRECORD *row = NULL;
- UINT r = ERROR_FUNCTION_FAILED;
- LPCWSTR val = NULL;
- DWORD len = 0;
-
- TRACE("%u %s %p %p\n", handle, debugstr_w(name),
- szValueBuf->str.w, pchValueBuf );
+ MSIRECORD *row;
+ WCHAR *nameW;
+ int len = 0;
+ UINT r;
if (!name)
return ERROR_INVALID_PARAMETER;
- package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
+ if (!(nameW = strdupAtoW(name)))
+ return ERROR_OUTOFMEMORY;
+
+ package = msihandle2msiinfo(hinst, MSIHANDLETYPE_PACKAGE);
if (!package)
{
- LPWSTR value = NULL, buffer;
+ WCHAR *value = NULL, *tmp;
MSIHANDLE remote;
+ DWORD len;
- if (!(remote = msi_get_remote(handle)))
+ if (!(remote = msi_get_remote(hinst)))
return ERROR_INVALID_HANDLE;
- r = remote_GetProperty(remote, name, &value, &len);
- if (r != ERROR_SUCCESS)
- return r;
-
- /* String might contain embedded nulls.
- * Native returns the correct size but truncates the string. */
- buffer = heap_alloc_zero((len + 1) * sizeof(WCHAR));
- if (!buffer)
+ r = remote_GetProperty(remote, nameW, &value, &len);
+ if (!r)
{
- midl_user_free(value);
- return ERROR_OUTOFMEMORY;
- }
- strcpyW(buffer, value);
-
- r = msi_strcpy_to_awstring(buffer, len, szValueBuf, pchValueBuf);
+ /* String might contain embedded nulls.
+ * Native returns the correct size but truncates the string. */
+ tmp = heap_alloc_zero((len + 1) * sizeof(WCHAR));
+ if (!tmp)
+ {
+ midl_user_free(value);
+ return ERROR_OUTOFMEMORY;
+ }
+ strcpyW(tmp, value);
- /* Bug required by Adobe installers */
- if (pchValueBuf && !szValueBuf->unicode && !szValueBuf->str.a)
- *pchValueBuf *= sizeof(WCHAR);
+ r = msi_strncpyWtoA(tmp, len, buf, sz, TRUE);
- heap_free(buffer);
+ heap_free(tmp);
+ }
midl_user_free(value);
+ heap_free(nameW);
return r;
}
- row = msi_get_property_row( package->db, name );
+ row = msi_get_property_row(package->db, nameW);
if (row)
- val = msi_record_get_string( row, 1, (int *)&len );
-
- if (!val)
- val = szEmpty;
+ value = msi_record_get_string(row, 1, &len);
- r = msi_strcpy_to_awstring( val, len, szValueBuf, pchValueBuf );
-
- if (row)
- msiobj_release( &row->hdr );
- msiobj_release( &package->hdr );
+ r = msi_strncpyWtoA(value, len, buf, sz, FALSE);
+ heap_free(nameW);
+ if (row) msiobj_release(&row->hdr);
+ msiobj_release(&package->hdr);
return r;
}
-UINT WINAPI MsiGetPropertyA(MSIHANDLE hinst, const char *name, char *buf, DWORD *sz)
+UINT WINAPI MsiGetPropertyW(MSIHANDLE hinst, const WCHAR *name, WCHAR *buf, DWORD *sz)
{
+ const WCHAR *value = szEmpty;
MSIPACKAGE *package;
- awstring val;
- WCHAR *nameW;
+ MSIRECORD *row;
+ int len = 0;
UINT r;
if (!name)
return ERROR_INVALID_PARAMETER;
- if (!(nameW = strdupAtoW(name)))
- return ERROR_OUTOFMEMORY;
-
package = msihandle2msiinfo(hinst, MSIHANDLETYPE_PACKAGE);
if (!package)
{
@@ -2433,7 +2425,7 @@ UINT WINAPI MsiGetPropertyA(MSIHANDLE hinst, const char *name, char *buf, DWORD
if (!(remote = msi_get_remote(hinst)))
return ERROR_INVALID_HANDLE;
- r = remote_GetProperty(remote, nameW, &value, &len);
+ r = remote_GetProperty(remote, name, &value, &len);
if (!r)
{
/* String might contain embedded nulls.
@@ -2446,36 +2438,25 @@ UINT WINAPI MsiGetPropertyA(MSIHANDLE hinst, const char *name, char *buf, DWORD
}
strcpyW(tmp, value);
- r = msi_strncpyWtoA(tmp, len, buf, sz, TRUE);
+ r = msi_strncpyW(tmp, len, buf, sz);
heap_free(tmp);
}
midl_user_free(value);
- heap_free(nameW);
return r;
}
- val.unicode = FALSE;
- val.str.a = buf;
+ row = msi_get_property_row(package->db, name);
+ if (row)
+ value = msi_record_get_string(row, 1, &len);
- r = MSI_GetProperty(hinst, nameW, &val, sz);
+ r = msi_strncpyW(value, len, buf, sz);
- heap_free(nameW);
+ if (row) msiobj_release(&row->hdr);
msiobj_release(&package->hdr);
return r;
}
-UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
- LPWSTR szValueBuf, LPDWORD pchValueBuf )
-{
- awstring val;
-
- val.unicode = TRUE;
- val.str.w = szValueBuf;
-
- return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );
-}
-
MSIHANDLE __cdecl s_remote_GetActiveDatabase(MSIHANDLE hinst)
{
return MsiGetActiveDatabase(hinst);
diff --git a/dlls/msi/tests/custom.c b/dlls/msi/tests/custom.c
index 96344eb..d240964 100644
--- a/dlls/msi/tests/custom.c
+++ b/dlls/msi/tests/custom.c
@@ -191,6 +191,12 @@ static void test_props(MSIHANDLE hinst)
ok(hinst, !strcmp(buffer, "xyz"), "got \"%s\"\n", buffer);
ok(hinst, sz == 3, "got size %u\n", sz);
+ r = MsiGetPropertyW(hinst, booW, NULL, NULL);
+ ok(hinst, !r, "got %u\n", r);
+
+ r = MsiGetPropertyW(hinst, booW, bufferW, NULL );
+ ok(hinst, r == ERROR_INVALID_PARAMETER, "got %u\n", r);
+
sz = 0;
r = MsiGetPropertyW(hinst, booW, NULL, &sz);
ok(hinst, !r, "got %u\n", r);
More information about the wine-cvs
mailing list