kernel32: Handle writing empty sections and keys in WritePrivateProfileString.

This commit is contained in:
James Hawkins 2009-03-22 14:37:44 -07:00 committed by Alexandre Julliard
parent f1308f9b40
commit 7c3529f1cc
2 changed files with 21 additions and 16 deletions

View File

@ -202,31 +202,31 @@ static void PROFILE_Save( HANDLE hFile, const PROFILESECTION *section, ENCODING
for ( ; section; section = section->next) for ( ; section; section = section->next)
{ {
int len = 0; int len = 4;
if (section->name[0]) len += strlenW(section->name) + 6; if (section->name[0]) len += strlenW(section->name);
for (key = section->key; key; key = key->next) for (key = section->key; key; key = key->next)
{ {
len += strlenW(key->name) + 2; len += strlenW(key->name);
if (key->value) len += strlenW(key->value) + 1; if (key->value && key->value[0]) len += strlenW(key->value);
len += 3; /* '=' and "\r\n" */
} }
buffer = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); buffer = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
if (!buffer) return; if (!buffer) return;
p = buffer; p = buffer;
*p++ = '[';
if (section->name[0]) if (section->name[0])
{ {
*p++ = '\r';
*p++ = '\n';
*p++ = '[';
strcpyW( p, section->name ); strcpyW( p, section->name );
p += strlenW(p); p += strlenW(p);
*p++ = ']';
*p++ = '\r';
*p++ = '\n';
} }
*p++ = ']';
*p++ = '\r';
*p++ = '\n';
for (key = section->key; key; key = key->next) for (key = section->key; key; key = key->next)
{ {
strcpyW( p, key->name ); strcpyW( p, key->name );
@ -587,12 +587,20 @@ static PROFILEKEY *PROFILE_Find( PROFILESECTION **section, LPCWSTR section_name,
int seclen, keylen; int seclen, keylen;
while (PROFILE_isspaceW(*section_name)) section_name++; while (PROFILE_isspaceW(*section_name)) section_name++;
p = section_name + strlenW(section_name) - 1; if (*section_name)
p = section_name + strlenW(section_name) - 1;
else
p = section_name;
while ((p > section_name) && PROFILE_isspaceW(*p)) p--; while ((p > section_name) && PROFILE_isspaceW(*p)) p--;
seclen = p - section_name + 1; seclen = p - section_name + 1;
while (PROFILE_isspaceW(*key_name)) key_name++; while (PROFILE_isspaceW(*key_name)) key_name++;
p = key_name + strlenW(key_name) - 1; if (*key_name)
p = key_name + strlenW(key_name) - 1;
else
p = key_name;
while ((p > key_name) && PROFILE_isspaceW(*p)) p--; while ((p > key_name) && PROFILE_isspaceW(*p)) p--;
keylen = p - key_name + 1; keylen = p - key_name + 1;

View File

@ -930,10 +930,7 @@ static void test_WritePrivateProfileString(void)
"key=string\r\n"; "key=string\r\n";
ret = WritePrivateProfileStringA("App", "key", "string", "win1.tmp"); ret = WritePrivateProfileStringA("App", "key", "string", "win1.tmp");
ok(ret == TRUE, "Expected TRUE, got %d\n", ret); ok(ret == TRUE, "Expected TRUE, got %d\n", ret);
todo_wine ok(check_file_data(path, data), "File doesn't match\n");
{
ok(check_file_data(path, data), "File doesn't match\n");
}
DeleteFileA(path); DeleteFileA(path);
GetTempPathA(MAX_PATH, temp); GetTempPathA(MAX_PATH, temp);