https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0abff65a5520d6e926d36…
commit 0abff65a5520d6e926d364edc6df6e10f2b46155
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sun Jan 3 00:10:03 2021 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sun Jan 3 00:27:54 2021 +0100
[USETUP] Minor improvements when initializing the console.
- Use NT values for uninitialized handle values.
- Cache the STD_INPUT_HANDLE.
- Free the console if GetConsoleScreenBufferInfo() fails in CONSOLE_Init().
---
base/setup/usetup/consup.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/base/setup/usetup/consup.c b/base/setup/usetup/consup.c
index 2a5336cb5e5..e72c43106e6 100644
--- a/base/setup/usetup/consup.c
+++ b/base/setup/usetup/consup.c
@@ -33,8 +33,8 @@
/* GLOBALS ******************************************************************/
-HANDLE StdInput = INVALID_HANDLE_VALUE;
-HANDLE StdOutput = INVALID_HANDLE_VALUE;
+HANDLE StdInput = NULL;
+HANDLE StdOutput = NULL;
SHORT xScreen = 0;
SHORT yScreen = 0;
@@ -45,15 +45,24 @@ BOOLEAN
CONSOLE_Init(VOID)
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
+
+ /* Allocate a new console */
if (!AllocConsole())
return FALSE;
- StdInput = GetStdHandle(STD_INPUT_HANDLE);
+ /* Get the standard handles */
+ StdInput = GetStdHandle(STD_INPUT_HANDLE);
StdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
+
+ /* Retrieve the size of the console */
if (!GetConsoleScreenBufferInfo(StdOutput, &csbi))
+ {
+ FreeConsole();
return FALSE;
+ }
xScreen = csbi.dwSize.X;
yScreen = csbi.dwSize.Y;
+
return TRUE;
}
@@ -175,7 +184,7 @@ CONSOLE_GetCursorXY(
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
- GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
+ GetConsoleScreenBufferInfo(StdOutput, &csbi);
*x = csbi.dwCursorPosition.X;
*y = csbi.dwCursorPosition.Y;