Hans Leidekker : msi: Don't terminate the string in msi_id2stringA.

Alexandre Julliard julliard at winehq.org
Thu May 31 13:30:40 CDT 2012


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

Author: Hans Leidekker <hans at codeweavers.com>
Date:   Thu May 31 10:05:14 2012 +0200

msi: Don't terminate the string in msi_id2stringA.

This makes sure that the last string can be fully written when saving the
string table.

---

 dlls/msi/string.c   |   32 ++++++++------------------------
 dlls/msi/tests/db.c |    2 +-
 2 files changed, 9 insertions(+), 25 deletions(-)

diff --git a/dlls/msi/string.c b/dlls/msi/string.c
index 4185c15..065c04a 100644
--- a/dlls/msi/string.c
+++ b/dlls/msi/string.c
@@ -357,14 +357,12 @@ const WCHAR *msi_string_lookup_id( const string_table *st, UINT id )
  *  [in/out] sz     - number of bytes available in the buffer on input
  *                    number of bytes used on output
  *
- *   The size includes the terminating nul character.  Short buffers
- *  will be filled, but not nul terminated.
+ *  Returned string is not nul terminated.
  */
 static UINT msi_id2stringA( const string_table *st, UINT id, LPSTR buffer, UINT *sz )
 {
-    UINT len;
+    UINT len, lenW;
     const WCHAR *str;
-    int n;
 
     TRACE("Finding string %d of %d\n", id, st->maxcount);
 
@@ -372,26 +370,14 @@ static UINT msi_id2stringA( const string_table *st, UINT id, LPSTR buffer, UINT
     if( !str )
         return ERROR_FUNCTION_FAILED;
 
-    len = WideCharToMultiByte( st->codepage, 0, str, -1, NULL, 0, NULL, NULL );
-
-    if( !buffer )
+    lenW = strlenW( str );
+    len = WideCharToMultiByte( st->codepage, 0, str, lenW, NULL, 0, NULL, NULL );
+    if( *sz < len )
     {
         *sz = len;
-        return ERROR_SUCCESS;
-    }
-
-    if( len > *sz )
-    {
-        n = strlenW( str ) + 1;
-        while( n && (len > *sz) )
-            len = WideCharToMultiByte( st->codepage, 0, 
-                           str, --n, NULL, 0, NULL, NULL );
+        return ERROR_MORE_DATA;
     }
-    else
-        n = -1;
-
-    *sz = WideCharToMultiByte( st->codepage, 0, str, n, buffer, len, NULL, NULL );
-
+    *sz = WideCharToMultiByte( st->codepage, 0, str, lenW, buffer, *sz, NULL, NULL );
     return ERROR_SUCCESS;
 }
 
@@ -588,7 +574,7 @@ UINT msi_save_string_table( const string_table *st, IStorage *storage, UINT *byt
     data = msi_alloc( datasize );
     if( ! data )
     {
-        WARN("Failed to alloc data %d bytes\n", poolsize );
+        WARN("Failed to alloc data %d bytes\n", datasize );
         goto err;
     }
 
@@ -622,8 +608,6 @@ UINT msi_save_string_table( const string_table *st, IStorage *storage, UINT *byt
             ERR("failed to fetch string\n");
             sz = 0;
         }
-        if( sz && (sz < (datasize - used ) ) )
-            sz--;
 
         if (sz)
             pool[ n*2 + 1 ] = st->strings[i].persistent_refcount;
diff --git a/dlls/msi/tests/db.c b/dlls/msi/tests/db.c
index 7a2fd7c..8b62c39 100644
--- a/dlls/msi/tests/db.c
+++ b/dlls/msi/tests/db.c
@@ -9345,7 +9345,7 @@ static void test_createtable(void)
         size = sizeof(buffer);
         res = MsiRecordGetString(hrec, 1, buffer, &size );
         ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
-        todo_wine ok(!strcmp(buffer,"b"), "b != %s\n", buffer);
+        ok(!strcmp(buffer,"b"), "b != %s\n", buffer);
 
         res = MsiCloseHandle( hrec );
         ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);




More information about the wine-cvs mailing list