Author: cwittich
Date: Sat Sep 13 03:23:32 2008
New Revision: 36179
URL:
http://svn.reactos.org/svn/reactos?rev=36179&view=rev
Log:
fix most kernel32_profile winetests
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] Sat Sep 13 03:23:32 2008
@@ -755,6 +755,9 @@
}
GetWindowsDirectoryW( windirW, MAX_PATH );
+
+ if (!filename)
+ filename = L"win.ini";
if ((RtlDetermineDosPathNameType_U(filename) == RtlPathTypeRelative) &&
!wcschr(filename, '\\') && !wcschr(filename, '/'))
@@ -933,7 +936,7 @@
while ((section!=NULL)) {
if (section->name[0]) {
tmplen = wcslen(section->name)+1;
- if (tmplen > buflen) {
+ if (tmplen >= buflen) {
if (buflen > 0) {
memcpy(buf, section->name, (buflen - 1) * sizeof(WCHAR));
buf += buflen - 1;
@@ -1111,9 +1114,6 @@
int ret;
LPCWSTR pDefVal = NULL;
- if (!filename)
- filename = L"win.ini";
-
DPRINT("%S, %S, %S, %p, %u, %S\n",
section, entry,
def_val, buffer, len, filename);
@@ -1337,7 +1337,13 @@
DWORD WINAPI GetPrivateProfileSectionW( LPCWSTR section, LPWSTR buffer,
DWORD len, LPCWSTR filename )
{
- int ret = 0;
+ int ret = 0;
+
+ if (!section || !buffer)
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return 0;
+ }
DPRINT("(%S, %p, %ld, %S)\n",
section, buffer, len, filename);
@@ -1363,18 +1369,23 @@
LPWSTR bufferW;
INT retW, ret = 0;
- bufferW = buffer ? HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)) : NULL;
- if (section) RtlCreateUnicodeStringFromAsciiz(§ionW, section);
- else sectionW.Buffer = NULL;
+ if (!section || !buffer)
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return 0;
+ }
+
+ bufferW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+ RtlCreateUnicodeStringFromAsciiz(§ionW, section);
if (filename) RtlCreateUnicodeStringFromAsciiz(&filenameW, filename);
else filenameW.Buffer = NULL;
retW = GetPrivateProfileSectionW(sectionW.Buffer, bufferW, len, filenameW.Buffer);
if (len > 2)
{
- ret = WideCharToMultiByte(CP_ACP, 0, bufferW, retW + 2, buffer, len, NULL,
NULL);
+ ret = WideCharToMultiByte(CP_ACP, 0, bufferW, retW + 1, buffer, len, NULL,
NULL);
if (ret > 2)
- ret -= 2;
+ ret -= 1;
else
{
ret = 0;
@@ -1645,13 +1656,17 @@
retW = GetPrivateProfileSectionNamesW(bufferW, size, filenameW.Buffer);
if (retW && size)
{
- ret = WideCharToMultiByte(CP_ACP, 0, bufferW, retW, buffer, size, NULL, NULL);
+ ret = WideCharToMultiByte(CP_ACP, 0, bufferW, retW+1, buffer, size-1, NULL,
NULL);
if (!ret)
{
- ret = size;
+ ret = size-2;
buffer[size-1] = 0;
}
- }
+ else
+ ret = ret-1;
+ }
+ else if(size)
+ buffer[0] = '\0';
RtlFreeUnicodeString(&filenameW);
HeapFree(GetProcessHeap(), 0, bufferW);