Patch 1/2 for SmartForms Installer: PROFILE_GetString incorrect return value

Joshua Thielen thielen at netprince.net
Fri Jun 21 23:18:07 CDT 2002


This patch fixes an error encountered in the Smart Forms installer 
(somewhat related to bug 575).

When calling GetPrivateProfileString with the second parameter as NULL, 
all of the keys under the specified section are copied to the buffer. 
The return value should be the number of characters copied minus the 
last null terminator. Since the keys are copied as null-terminated 
strings with the last string terminated with two null characters, strlen 
cannot be used to determine the number of characters copied. This patch 
corrects PROFILE_GetString for this case.

Josh Thielen


-------------- next part --------------
Index: wine/files/profile.c
===================================================================
RCS file: /home/wine/wine/files/profile.c,v
retrieving revision 1.70
diff -u -r1.70 profile.c
--- wine/files/profile.c	20 Jun 2002 23:21:27 -0000	1.70
+++ wine/files/profile.c	22 Jun 2002 03:42:37 -0000
@@ -841,6 +841,7 @@
 static INT PROFILE_GetString( LPCSTR section, LPCSTR key_name,
 			      LPCSTR def_val, LPSTR buffer, UINT len )
 {
+    int i;
     PROFILEKEY *key = NULL;
 
     if(!buffer) return 0;
@@ -848,9 +849,11 @@
     if (!def_val) def_val = "";
     if (key_name)
     {
-	if (!key_name[0])
+        if (!key_name[0])
+        {
             /* Win95 returns 0 on keyname "". Tested with Likse32 bon 000227 */
             return 0;
+        }
         key = PROFILE_Find( &CurProfile->section, section, key_name, FALSE, FALSE);
         PROFILE_CopyEntry( buffer, (key && key->value) ? key->value : def_val,
                            len, FALSE );
@@ -863,9 +866,26 @@
     {
         PROFILE_GetSection(CurProfile->section, section, buffer, len,
 				FALSE, FALSE);
-	if (!buffer[0]) /* no luck -> def_val */
-	    PROFILE_CopyEntry(buffer, def_val, len, FALSE);
-	return strlen(buffer);
+        if (!buffer[0]) 
+        {
+            /* no luck -> def_val */
+            PROFILE_CopyEntry(buffer, def_val, len, FALSE);
+        }
+        if(!key_name) 
+        {
+            /* 
+             * Return the number of characters copied not including the 
+             * second null character of the two null character termination. 
+             */
+            for(i = 1; i < len; i++) 
+            {
+                if(!buffer[i] && !buffer[i - 1]) return i;
+            }
+        }
+        else
+        {
+            return strlen(buffer);
+        }
     }
     buffer[0] = '\0';
     return 0;


More information about the wine-patches mailing list