Zhiyi Zhang : kernel32: Fix handling lines with only values in GetPrivateProfileSection.

Alexandre Julliard julliard at winehq.org
Mon May 14 06:54:24 CDT 2018


Module: wine
Branch: stable
Commit: ac54f3a5b0f9ee6c970d6184ce0121ab54820480
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=ac54f3a5b0f9ee6c970d6184ce0121ab54820480

Author: Zhiyi Zhang <yi.gd.cn at gmail.com>
Date:   Tue Mar  6 16:13:20 2018 +0800

kernel32: Fix handling lines with only values in GetPrivateProfileSection.

Signed-off-by: Zhiyi Zhang <zzhang at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit aa16304c191ab19a60577f02f42b904df584acaf)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>

---

 dlls/kernel32/profile.c       |  2 +-
 dlls/kernel32/tests/profile.c | 15 ++++++++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/dlls/kernel32/profile.c b/dlls/kernel32/profile.c
index 721808c..0974aaf 100644
--- a/dlls/kernel32/profile.c
+++ b/dlls/kernel32/profile.c
@@ -879,7 +879,7 @@ static INT PROFILE_GetSection( PROFILESECTION *section, LPCWSTR section_name,
             for (key = section->key; key; key = key->next)
             {
                 if (len <= 2) break;
-                if (!*key->name) continue;  /* Skip empty lines */
+                if (!*key->name && !key->value) continue;  /* Skip empty lines */
                 if (IS_ENTRY_COMMENT(key->name)) continue;  /* Skip comments */
                 if (!return_values && !key->value) continue;  /* Skip lines w.o. '=' */
                 PROFILE_CopyEntry( buffer, key->name, len - 1, 0 );
diff --git a/dlls/kernel32/tests/profile.c b/dlls/kernel32/tests/profile.c
index 17ba124..64ffc17 100644
--- a/dlls/kernel32/tests/profile.c
+++ b/dlls/kernel32/tests/profile.c
@@ -171,7 +171,7 @@ static void test_profile_sections(void)
     DWORD count;
     char buf[100];
     char *p;
-    static const char content[]="[section1]\r\nname1=val1\r\nname2=\r\nname3\r\nname4=val4\r\n[section2]\r\n";
+    static const char content[]="[section1]\r\nname1=val1\r\nname2=\r\nname3\r\nname4=val4\r\n[section2]\r\n[section3]\r\n=val5\r\n";
     static const char testfile4[]=".\\testwine4.ini";
     BOOL on_win98 = FALSE;
 
@@ -241,6 +241,19 @@ static void test_profile_sections(void)
         broken(GetLastError() == 0xdeadbeef), /* Win9x, WinME */
         "expected ERROR_SUCCESS, got %d\n", GetLastError());
 
+    /* Existing section with no keys but has values */
+    SetLastError(0xdeadbeef);
+    ret=GetPrivateProfileSectionA("section3", buf, sizeof(buf), testfile4);
+    trace("section3 return: %s\n", buf);
+    for( p = buf + strlen(buf) + 1; *p;p += strlen(p)+1)
+        p[-1] = ',';
+    ok( ret == 6 && !strcmp( buf, "=val5"), "wrong section returned(%d): %s\n",
+            ret, buf);
+    ok( buf[ret-1] == 0 && buf[ret] == 0, "returned buffer not terminated with double-null\n" );
+    ok( GetLastError() == ERROR_SUCCESS ||
+        broken(GetLastError() == 0xdeadbeef), /* Win9x, WinME */
+        "expected ERROR_SUCCESS, got %d\n", GetLastError());
+
     /* Overflow*/
     ret=GetPrivateProfileSectionA("section1", buf, 24, testfile4);
     for( p = buf + strlen(buf) + 1; *p;p += strlen(p)+1)




More information about the wine-cvs mailing list