Author: cwittich
Date: Mon Apr 13 22:53:56 2009
New Revision: 40488
URL:
http://svn.reactos.org/svn/reactos?rev=40488&view=rev
Log:
James Hawkins : kernel32: Handle writing empty sections and keys in
WritePrivateProfileString.
Modified:
trunk/reactos/dll/win32/kernel32/misc/profile.c
Modified: trunk/reactos/dll/win32/kernel32/misc/profile.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/misc/pr…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/misc/profile.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/misc/profile.c [iso-8859-1] Mon Apr 13 22:53:56 2009
@@ -213,31 +213,31 @@
for ( ; section; section = section->next)
{
- int len = 0;
-
- if (section->name[0]) len += wcslen(section->name) + 6;
+ int len = 4;
+
+ if (section->name[0]) len += wcslen(section->name);
for (key = section->key; key; key = key->next)
{
- len += wcslen(key->name) + 2;
- if (key->value) len += wcslen(key->value) + 1;
+ len += wcslen(key->name);
+ if (key->value && key->value[0]) len += wcslen(key->value);
+ len += 3; /* '=' and "\r\n" */
}
buffer = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
if (!buffer) return;
p = buffer;
+ *p++ = '[';
if (section->name[0])
{
- *p++ = '\r';
- *p++ = '\n';
- *p++ = '[';
wcscpy( p, section->name );
p += wcslen(p);
- *p++ = ']';
- *p++ = '\r';
- *p++ = '\n';
- }
+ }
+ *p++ = ']';
+ *p++ = '\r';
+ *p++ = '\n';
+
for (key = section->key; key; key = key->next)
{
wcscpy( p, key->name );
@@ -607,12 +607,20 @@
int seclen, keylen;
while (PROFILE_isspaceW(*section_name)) section_name++;
- p = section_name + wcslen(section_name) - 1;
+ if (*section_name)
+ p = section_name + wcslen(section_name) - 1;
+ else
+ p = section_name;
+
while ((p > section_name) && PROFILE_isspaceW(*p)) p--;
seclen = p - section_name + 1;
while (PROFILE_isspaceW(*key_name)) key_name++;
- p = key_name + wcslen(key_name) - 1;
+ if (*key_name)
+ p = key_name + wcslen(key_name) - 1;
+ else
+ p = key_name;
+
while ((p > key_name) && PROFILE_isspaceW(*p)) p--;
keylen = p - key_name + 1;