Get(Private)ProfileString fix when enumerating keys.
Rein Klazes
wijn at wanadoo.nl
Tue Mar 1 03:00:29 CST 2005
Hi,
This fixes a "damaged setup file" error in Microsoft's snapshot viewer.
Changelog:
dlls/kernel : profile.c
dlls/kernel/tests : profile.c
When enumerating keys using Get(Private)ProfileString do not
include lines without an '=' character. Added a test that shows
the behavior.
Rein.
-------------- next part --------------
--- wine/dlls/kernel/profile.c 2005-02-10 22:22:31.000000000 +0100
+++ mywine/dlls/kernel/profile.c 2005-03-01 08:47:38.000000000 +0100
@@ -863,6 +863,7 @@ static INT PROFILE_GetSection( PROFILESE
if (len <= 2) break;
if (!*key->name) continue; /* Skip empty lines */
if (IS_ENTRY_COMMENT(key->name)) continue; /* Skip comments */
+ if (!key->value) continue; /* Skip lines w.o. '=' */
PROFILE_CopyEntry( buffer, key->name, len - 1, 0 );
len -= strlenW(buffer) + 1;
buffer += strlenW(buffer) + 1;
--- wine/dlls/kernel/tests/profile.c 2004-06-18 01:00:54.000000000 +0200
+++ mywine/dlls/kernel/tests/profile.c 2005-03-01 08:45:43.000000000 +0100
@@ -28,6 +28,7 @@
#define KEY "ProfileInt"
#define SECTION "Test"
#define TESTFILE ".\\testwine.ini"
+#define TESTFILE2 ".\\testwine2.ini"
struct _profileInt {
LPCSTR section;
@@ -88,7 +89,44 @@ static void test_profile_int(void)
DeleteFileA( TESTFILE);
}
+void test_profile_string()
+{
+ HANDLE h;
+ int ret;
+ DWORD count;
+ char buf[100];
+ char *p;
+ /* test that lines without an '=' will not be enumerated */
+ /* in the case below, name2 is a key while name3 is not. */
+ char content[]="[s]\r\nname1=val1\r\nname2=\r\nname3\r\nname4=val4\r\n";
+ DeleteFileA( TESTFILE2);
+ h = CreateFileA( TESTFILE2, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL, NULL);
+ ok( h != INVALID_HANDLE_VALUE, " cannot create %s\n", TESTFILE2);
+ if( h == INVALID_HANDLE_VALUE) return;
+ WriteFile( h, content, sizeof(content), &count, NULL);
+ CloseHandle( h);
+ /* enumerate the keys */
+ ret=GetPrivateProfileStringA( "s", NULL, "", buf, sizeof(buf),
+ TESTFILE2);
+ for( p = buf + strlen(buf) + 1; *p;p += strlen(p)+1)
+ p[-1] = ',';
+ /* and test */
+ ok( !strcmp( buf, "name1,name2,name4"), "wrong keys returned: %s\n",
+ buf);
+ /* add a new key to test that the file is quite usable */
+ WritePrivateProfileStringA( "s", "name5", "val5", TESTFILE2);
+ ret=GetPrivateProfileStringA( "s", NULL, "", buf, sizeof(buf),
+ TESTFILE2);
+ for( p = buf + strlen(buf) + 1; *p;p += strlen(p)+1)
+ p[-1] = ',';
+ ok( !strcmp( buf, "name1,name2,name4,name5"), "wrong keys returned: %s\n",
+ buf);
+ DeleteFileA( TESTFILE2);
+}
+
START_TEST(profile)
{
test_profile_int();
+ test_profile_string();
}
More information about the wine-patches
mailing list