[KERNEL32]
authorThomas Faber <thomas.faber@reactos.org>
Tue, 26 Nov 2013 15:09:21 +0000 (15:09 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Tue, 26 Nov 2013 15:09:21 +0000 (15:09 +0000)
- Fix wrong check for realtime priority class in CreateProcessInternalW
- Fix double free in GetEnvironmentVariable[AW]
- Fix broken sizeof usage ('X' is of type int!)
- Remove redundant casts and comparisons

svn path=/trunk/; revision=61101

reactos/dll/win32/kernel32/client/environ.c
reactos/dll/win32/kernel32/client/proc.c

index e1c191d..69d6828 100644 (file)
@@ -83,10 +83,10 @@ GetEnvironmentVariableA(IN LPCSTR lpName,
     if ((NT_SUCCESS(Status)) && !(nSize)) Status = STATUS_BUFFER_TOO_SMALL;
 
     /* Check if we didn't have enough space */
-    if (!(NT_SUCCESS(Status)) && (Status == STATUS_BUFFER_TOO_SMALL))
+    if (Status == STATUS_BUFFER_TOO_SMALL)
     {
         /* Fixup the length that the API returned */
-        VarValueU.MaximumLength = VarValueU.Length + 2;
+        VarValueU.MaximumLength = VarValueU.Length + sizeof(UNICODE_NULL);
 
         /* Free old Unicode buffer */
         RtlFreeHeap(RtlGetProcessHeap(), 0, VarValueU.Buffer);
@@ -108,6 +108,7 @@ GetEnvironmentVariableA(IN LPCSTR lpName,
         {
             /* Set failure status */
             Status = STATUS_NO_MEMORY;
+            VarValueU.Buffer = NULL;
         }
     }
     else if (NT_SUCCESS(Status))
@@ -373,7 +374,7 @@ BOOL
 WINAPI
 FreeEnvironmentStringsA(IN LPSTR EnvironmentStrings)
 {
-    return (BOOL)RtlFreeHeap(RtlGetProcessHeap(), 0, EnvironmentStrings);
+    return RtlFreeHeap(RtlGetProcessHeap(), 0, EnvironmentStrings);
 }
 
 /*
@@ -383,7 +384,7 @@ BOOL
 WINAPI
 FreeEnvironmentStringsW(IN LPWSTR EnvironmentStrings)
 {
-    return (BOOL)RtlFreeHeap(RtlGetProcessHeap(), 0, EnvironmentStrings);
+    return RtlFreeHeap(RtlGetProcessHeap(), 0, EnvironmentStrings);
 }
 
 /*
@@ -443,7 +444,7 @@ ExpandEnvironmentStringsA(IN LPCSTR lpSrc,
     Status = RtlExpandEnvironmentStrings_U(NULL, &SourceU, &DestU, &Length);
 
     /* Check if we didn't have enough space */
-    if (!(NT_SUCCESS(Status)) && (Status == STATUS_BUFFER_TOO_SMALL))
+    if (Status == STATUS_BUFFER_TOO_SMALL)
     {
         /* Fixup the length that the API returned */
         DestU.MaximumLength = (SHORT)Length;
@@ -468,6 +469,7 @@ ExpandEnvironmentStringsA(IN LPCSTR lpSrc,
         {
             /* Set failure status */
             Status = STATUS_NO_MEMORY;
+            DestU.Buffer = NULL;
         }
     }
     else if (NT_SUCCESS(Status))
@@ -518,8 +520,7 @@ ExpandEnvironmentStringsW(IN LPCWSTR lpSrc,
     NTSTATUS Status;
     USHORT UniSize;
 
-    UniSize = UNICODE_STRING_MAX_CHARS - 2;
-    if (nSize <= UniSize) UniSize = (USHORT)nSize;
+    UniSize = min(nSize, UNICODE_STRING_MAX_CHARS - 2);
 
     RtlInitUnicodeString(&Source, (LPWSTR)lpSrc);
     RtlInitEmptyUnicodeString(&Destination, lpDst, UniSize * sizeof(WCHAR));
index 4672755..23ccfbd 100644 (file)
@@ -3762,7 +3762,7 @@ StartScan:
         }
 
         /* Account for the quotes and space between the two */
-        n += ((sizeof('""') * 2) + sizeof(' '));
+        n += sizeof("\" \"") - sizeof(ANSI_NULL);
 
         /* Convert to bytes, and make sure we don't overflow */
         n *= sizeof(WCHAR);
@@ -3923,7 +3923,7 @@ StartScan:
         RealTimePrivilegeState = NULL;
 
         /* Is realtime priority being requested? */
-        if (PriorityClass.PriorityClass == REALTIME_PRIORITY_CLASS)
+        if (PriorityClass.PriorityClass == PROCESS_PRIORITY_CLASS_REALTIME)
         {
             /* Check if the caller has real-time access, and enable it if so */
             RealTimePrivilegeState = BasepIsRealtimeAllowed(TRUE);