fix some kernel32 module winetests (GetProcAddress, GetModuleFileName)
authorChristoph von Wittich <christoph_vw@reactos.org>
Sat, 13 Sep 2008 07:37:05 +0000 (07:37 +0000)
committerChristoph von Wittich <christoph_vw@reactos.org>
Sat, 13 Sep 2008 07:37:05 +0000 (07:37 +0000)
svn path=/trunk/; revision=36178

reactos/dll/win32/kernel32/misc/ldr.c

index 985bc1c..6647694 100644 (file)
@@ -230,24 +230,31 @@ GetProcAddress( HMODULE hModule, LPCSTR lpProcName )
 {
        ANSI_STRING ProcedureName;
        FARPROC fnExp = NULL;
+       NTSTATUS Status;
 
        if (HIWORD(lpProcName) != 0)
        {
                RtlInitAnsiString (&ProcedureName,
                                   (LPSTR)lpProcName);
-               LdrGetProcedureAddress ((PVOID)hModule,
+               Status = LdrGetProcedureAddress ((PVOID)hModule,
                                        &ProcedureName,
                                        0,
                                        (PVOID*)&fnExp);
        }
        else
        {
-               LdrGetProcedureAddress ((PVOID)hModule,
+               Status = LdrGetProcedureAddress ((PVOID)hModule,
                                        NULL,
                                        (ULONG)lpProcName,
                                        (PVOID*)&fnExp);
        }
 
+       if (!NT_SUCCESS(Status))
+       {
+               SetLastError( RtlNtStatusToDosError( Status ) );
+               fnExp = NULL;
+       }
+
        return fnExp;
 }
 
@@ -313,27 +320,25 @@ GetModuleFileNameA (
                Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
                if (Module->DllBase == (PVOID)hModule)
                {
-                       if (nSize * sizeof(WCHAR) < Module->FullDllName.Length)
-                       {
+                       Length = min(nSize, Module->FullDllName.Length / sizeof(WCHAR));
+                       FileName.Length = 0;
+                       FileName.MaximumLength = (USHORT)Length * sizeof(WCHAR);
+                       FileName.Buffer = lpFilename;
+
+                       /* convert unicode string to ansi (or oem) */
+                       if (bIsFileApiAnsi)
+                               RtlUnicodeStringToAnsiString (&FileName,
+                                                             &Module->FullDllName,
+                                                             FALSE);
+                       else
+                               RtlUnicodeStringToOemString (&FileName,
+                                                            &Module->FullDllName,
+                                                            FALSE);
+                               
+                       if (nSize < Length)
                                SetLastErrorByStatus (STATUS_BUFFER_TOO_SMALL);
-                       }
                        else
-                       {
-                               FileName.Length = 0;
-                               FileName.MaximumLength = (USHORT)nSize * sizeof(WCHAR);
-                               FileName.Buffer = lpFilename;
-
-                               /* convert unicode string to ansi (or oem) */
-                               if (bIsFileApiAnsi)
-                                       RtlUnicodeStringToAnsiString (&FileName,
-                                                                     &Module->FullDllName,
-                                                                     FALSE);
-                               else
-                                       RtlUnicodeStringToOemString (&FileName,
-                                                                    &Module->FullDllName,
-                                                                    FALSE);
-                               Length = Module->FullDllName.Length / sizeof(WCHAR);
-                       }
+                               lpFilename[Length] = '\0';
 
                        RtlLeaveCriticalSection (Peb->LoaderLock);
                        return Length;
@@ -381,22 +386,20 @@ GetModuleFileNameW (
 
                if (Module->DllBase == (PVOID)hModule)
                {
-                       if (nSize * sizeof(WCHAR) < Module->FullDllName.Length)
-                       {
+                       Length = min(nSize, Module->FullDllName.Length / sizeof(WCHAR));
+                       FileName.Length = 0;
+                       FileName.MaximumLength = (USHORT) Length * sizeof(WCHAR);
+                       FileName.Buffer = lpFilename;
+
+                       RtlCopyUnicodeString (&FileName,
+                                             &Module->FullDllName);
+                       if (nSize < Length)
                                SetLastErrorByStatus (STATUS_BUFFER_TOO_SMALL);
-                       }
                        else
-                       {
-                               FileName.Length = 0;
-                               FileName.MaximumLength =(USHORT)nSize * sizeof(WCHAR);
-                               FileName.Buffer = lpFilename;
-
-                               RtlCopyUnicodeString (&FileName,
-                                                     &Module->FullDllName);
-                               Length = Module->FullDllName.Length / sizeof(WCHAR);
-                       }
+                               lpFilename[Length] = L'\0';
 
                        RtlLeaveCriticalSection (Peb->LoaderLock);
+
                        return Length;
                }