diff --git a/reactos/dll/win32/kernel32/client/environ.c b/reactos/dll/win32/kernel32/client/environ.c index e1c191d8dd8..69d68280403 100644 --- a/reactos/dll/win32/kernel32/client/environ.c +++ b/reactos/dll/win32/kernel32/client/environ.c @@ -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)); diff --git a/reactos/dll/win32/kernel32/client/proc.c b/reactos/dll/win32/kernel32/client/proc.c index 46727559292..23ccfbd5653 100644 --- a/reactos/dll/win32/kernel32/client/proc.c +++ b/reactos/dll/win32/kernel32/client/proc.c @@ -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);