Skip to content

Commit be678a5

Browse files
Claudio Fontanajulliard
authored andcommitted
kernel32: Allow empty profile section and key name strings.
Consider "" a normal section, and fix calculation for zero length section name string and key name string. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=8036 Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=18099 Signed-off-by: Claudio Fontana <[email protected]> Signed-off-by: Vijay Kiran Kamuju <[email protected]> Signed-off-by: Alexandre Julliard <[email protected]>
1 parent 31f2a18 commit be678a5

2 files changed

Lines changed: 16 additions & 26 deletions

File tree

dlls/kernel32/profile.c

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ static BOOL PROFILE_DeleteSection( PROFILESECTION **section, LPCWSTR name )
500500
{
501501
while (*section)
502502
{
503-
if ((*section)->name[0] && !strcmpiW( (*section)->name, name ))
503+
if (!strcmpiW( (*section)->name, name ))
504504
{
505505
PROFILESECTION *to_del = *section;
506506
*section = to_del->next;
@@ -524,7 +524,7 @@ static BOOL PROFILE_DeleteKey( PROFILESECTION **section,
524524
{
525525
while (*section)
526526
{
527-
if ((*section)->name[0] && !strcmpiW( (*section)->name, section_name ))
527+
if (!strcmpiW( (*section)->name, section_name ))
528528
{
529529
PROFILEKEY **key = &(*section)->key;
530530
while (*key)
@@ -556,7 +556,7 @@ static void PROFILE_DeleteAllKeys( LPCWSTR section_name)
556556
PROFILESECTION **section= &CurProfile->section;
557557
while (*section)
558558
{
559-
if ((*section)->name[0] && !strcmpiW( (*section)->name, section_name ))
559+
if (!strcmpiW( (*section)->name, section_name ))
560560
{
561561
PROFILEKEY **key = &(*section)->key;
562562
while (*key)
@@ -582,31 +582,28 @@ static PROFILEKEY *PROFILE_Find( PROFILESECTION **section, LPCWSTR section_name,
582582
LPCWSTR key_name, BOOL create, BOOL create_always )
583583
{
584584
LPCWSTR p;
585-
int seclen, keylen;
585+
int seclen = 0, keylen = 0;
586586

587587
while (PROFILE_isspaceW(*section_name)) section_name++;
588588
if (*section_name)
589+
{
589590
p = section_name + strlenW(section_name) - 1;
590-
else
591-
p = section_name;
592-
593-
while ((p > section_name) && PROFILE_isspaceW(*p)) p--;
594-
seclen = p - section_name + 1;
591+
while ((p > section_name) && PROFILE_isspaceW(*p)) p--;
592+
seclen = p - section_name + 1;
593+
}
595594

596595
while (PROFILE_isspaceW(*key_name)) key_name++;
597596
if (*key_name)
597+
{
598598
p = key_name + strlenW(key_name) - 1;
599-
else
600-
p = key_name;
601-
602-
while ((p > key_name) && PROFILE_isspaceW(*p)) p--;
603-
keylen = p - key_name + 1;
599+
while ((p > key_name) && PROFILE_isspaceW(*p)) p--;
600+
keylen = p - key_name + 1;
601+
}
604602

605603
while (*section)
606604
{
607-
if ( ((*section)->name[0])
608-
&& (!(strncmpiW( (*section)->name, section_name, seclen )))
609-
&& (((*section)->name)[seclen] == '\0') )
605+
if (!strncmpiW((*section)->name, section_name, seclen) &&
606+
((*section)->name)[seclen] == '\0')
610607
{
611608
PROFILEKEY **key = &(*section)->key;
612609

@@ -873,7 +870,7 @@ static INT PROFILE_GetSection( PROFILESECTION *section, LPCWSTR section_name,
873870

874871
while (section)
875872
{
876-
if (section->name[0] && !strcmpiW( section->name, section_name ))
873+
if (!strcmpiW( section->name, section_name ))
877874
{
878875
UINT oldlen = len;
879876
for (key = section->key; key; key = key->next)
@@ -988,11 +985,6 @@ static INT PROFILE_GetString( LPCWSTR section, LPCWSTR key_name,
988985
if (!def_val) def_val = empty_strW;
989986
if (key_name)
990987
{
991-
if (!key_name[0])
992-
{
993-
PROFILE_CopyEntry(buffer, def_val, len, TRUE);
994-
return strlenW(buffer);
995-
}
996988
key = PROFILE_Find( &CurProfile->section, section, key_name, FALSE, FALSE);
997989
PROFILE_CopyEntry( buffer, (key && key->value) ? key->value : def_val,
998990
len, TRUE );
@@ -1002,7 +994,7 @@ static INT PROFILE_GetString( LPCWSTR section, LPCWSTR key_name,
1002994
return strlenW( buffer );
1003995
}
1004996
/* no "else" here ! */
1005-
if (section && section[0])
997+
if (section)
1006998
{
1007999
INT ret = PROFILE_GetSection(CurProfile->section, section, buffer, len, FALSE);
10081000
if (!buffer[0]) /* no luck -> def_val */

dlls/kernel32/tests/profile.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,7 @@ static void test_profile_string(void)
153153

154154
/* works only in unicode, ascii crashes */
155155
ret=GetPrivateProfileStringW(sW, emptyW, emptyW, bufW, ARRAY_SIZE(bufW), TESTFILE2W);
156-
todo_wine
157156
ok(ret == 10, "expected 10, got %u\n", ret);
158-
todo_wine
159157
ok(!lstrcmpW(valnokeyW,bufW), "expected %s, got %s\n",
160158
wine_dbgstr_w(valnokeyW), wine_dbgstr_w(bufW) );
161159

0 commit comments

Comments
 (0)