[KERNEL32][CONSRV] Use more often the internal ConioRectHeight/Width() and ConioIsRectEmpty() macros.

This commit is contained in:
Hermès Bélusca-Maïto 2020-02-22 21:15:58 +01:00
parent 05053b6f18
commit 570eba2a52
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
6 changed files with 22 additions and 26 deletions

View file

@ -20,9 +20,9 @@
/* See consrv/include/rect.h */ /* See consrv/include/rect.h */
#define ConioRectHeight(Rect) \ #define ConioRectHeight(Rect) \
(((Rect)->Top) > ((Rect)->Bottom) ? 0 : ((Rect)->Bottom) - ((Rect)->Top) + 1) (((Rect)->Top > (Rect)->Bottom) ? 0 : ((Rect)->Bottom - (Rect)->Top + 1))
#define ConioRectWidth(Rect) \ #define ConioRectWidth(Rect) \
(((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 1) (((Rect)->Left > (Rect)->Right) ? 0 : ((Rect)->Right - (Rect)->Left + 1))
/* PRIVATE FUNCTIONS **********************************************************/ /* PRIVATE FUNCTIONS **********************************************************/
@ -436,8 +436,7 @@ IntReadConsoleOutput(IN HANDLE hConsoleOutput,
/* Copy into the buffer */ /* Copy into the buffer */
SizeX = ReadOutputRequest->ReadRegion.Right - SizeX = ConioRectWidth(&ReadOutputRequest->ReadRegion);
ReadOutputRequest->ReadRegion.Left + 1;
for (y = 0, Y = ReadOutputRequest->ReadRegion.Top; Y <= ReadOutputRequest->ReadRegion.Bottom; ++y, ++Y) for (y = 0, Y = ReadOutputRequest->ReadRegion.Top; Y <= ReadOutputRequest->ReadRegion.Bottom; ++y, ++Y)
{ {
@ -913,8 +912,7 @@ IntWriteConsoleOutput(IN HANDLE hConsoleOutput,
/* Copy into the buffer */ /* Copy into the buffer */
SizeX = WriteOutputRequest->WriteRegion.Right - SizeX = ConioRectWidth(&WriteOutputRequest->WriteRegion);
WriteOutputRequest->WriteRegion.Left + 1;
for (y = 0, Y = WriteOutputRequest->WriteRegion.Top; Y <= WriteOutputRequest->WriteRegion.Bottom; ++y, ++Y) for (y = 0, Y = WriteOutputRequest->WriteRegion.Top; Y <= WriteOutputRequest->WriteRegion.Bottom; ++y, ++Y)
{ {

View file

@ -1607,15 +1607,14 @@ ConDrvSetConsoleWindowInfo(IN PCONSOLE Console,
} }
/* /*
* The MSDN documentation on SetConsoleWindowInfo is partially wrong about * The MSDN documentation on SetConsoleWindowInfo() is partially wrong about
* the performed checks this API performs. While it is correct that the * the performed checks this API performs. While it is correct that the
* 'Right'/'Bottom' members cannot be strictly smaller than the 'Left'/'Top' * 'Right'/'Bottom' members cannot be strictly smaller than the 'Left'/'Top'
* members, they can be equal. * members (the rectangle cannot be empty), they can be equal (describe one cell).
* Also, if the 'Left' or 'Top' members are negative, this is automatically * Also, if the 'Left' or 'Top' members are negative, this is automatically
* corrected for, and the window rectangle coordinates are shifted accordingly. * corrected for, and the window rectangle coordinates are shifted accordingly.
*/ */
if ((CapturedWindowRect.Right < CapturedWindowRect.Left) || if (ConioIsRectEmpty(&CapturedWindowRect))
(CapturedWindowRect.Bottom < CapturedWindowRect.Top))
{ {
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
@ -1627,8 +1626,8 @@ ConDrvSetConsoleWindowInfo(IN PCONSOLE Console,
TermGetLargestConsoleWindowSize(Console, &LargestWindowSize); TermGetLargestConsoleWindowSize(Console, &LargestWindowSize);
LargestWindowSize.X = min(LargestWindowSize.X, Buffer->ScreenBufferSize.X); LargestWindowSize.X = min(LargestWindowSize.X, Buffer->ScreenBufferSize.X);
LargestWindowSize.Y = min(LargestWindowSize.Y, Buffer->ScreenBufferSize.Y); LargestWindowSize.Y = min(LargestWindowSize.Y, Buffer->ScreenBufferSize.Y);
if ((CapturedWindowRect.Right - CapturedWindowRect.Left + 1 > LargestWindowSize.X) || if ((ConioRectWidth(&CapturedWindowRect) > LargestWindowSize.X) ||
(CapturedWindowRect.Bottom - CapturedWindowRect.Top + 1 > LargestWindowSize.Y)) (ConioRectHeight(&CapturedWindowRect) > LargestWindowSize.Y))
{ {
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
@ -1652,8 +1651,8 @@ ConDrvSetConsoleWindowInfo(IN PCONSOLE Console,
Buffer->ViewOrigin.X = CapturedWindowRect.Left; Buffer->ViewOrigin.X = CapturedWindowRect.Left;
Buffer->ViewOrigin.Y = CapturedWindowRect.Top; Buffer->ViewOrigin.Y = CapturedWindowRect.Top;
Buffer->ViewSize.X = CapturedWindowRect.Right - CapturedWindowRect.Left + 1; Buffer->ViewSize.X = ConioRectWidth(&CapturedWindowRect);
Buffer->ViewSize.Y = CapturedWindowRect.Bottom - CapturedWindowRect.Top + 1; Buffer->ViewSize.Y = ConioRectHeight(&CapturedWindowRect);
TermResizeTerminal(Console); TermResizeTerminal(Console);

View file

@ -497,8 +497,8 @@ CSR_API(SrvReadConsoleOutput)
DPRINT("SrvReadConsoleOutput\n"); DPRINT("SrvReadConsoleOutput\n");
NumCells = (ReadOutputRequest->ReadRegion.Right - ReadOutputRequest->ReadRegion.Left + 1) * NumCells = ConioRectWidth(&ReadOutputRequest->ReadRegion) *
(ReadOutputRequest->ReadRegion.Bottom - ReadOutputRequest->ReadRegion.Top + 1); ConioRectHeight(&ReadOutputRequest->ReadRegion);
/* /*
* For optimization purposes, Windows (and hence ReactOS, too, for * For optimization purposes, Windows (and hence ReactOS, too, for
@ -562,8 +562,8 @@ CSR_API(SrvWriteConsoleOutput)
DPRINT("SrvWriteConsoleOutput\n"); DPRINT("SrvWriteConsoleOutput\n");
NumCells = (WriteOutputRequest->WriteRegion.Right - WriteOutputRequest->WriteRegion.Left + 1) * NumCells = ConioRectWidth(&WriteOutputRequest->WriteRegion) *
(WriteOutputRequest->WriteRegion.Bottom - WriteOutputRequest->WriteRegion.Top + 1); ConioRectHeight(&WriteOutputRequest->WriteRegion);
Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(Process), Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(Process),
WriteOutputRequest->OutputHandle, WriteOutputRequest->OutputHandle,

View file

@ -32,8 +32,8 @@ GuiCopyFromGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer,
if (Buffer->BitMap == NULL) return; if (Buffer->BitMap == NULL) return;
selWidth = GuiData->Selection.srSelection.Right - GuiData->Selection.srSelection.Left + 1; selWidth = ConioRectWidth(&GuiData->Selection.srSelection);
selHeight = GuiData->Selection.srSelection.Bottom - GuiData->Selection.srSelection.Top + 1; selHeight = ConioRectHeight(&GuiData->Selection.srSelection);
DPRINT("Selection is (%d|%d) to (%d|%d)\n", DPRINT("Selection is (%d|%d) to (%d|%d)\n",
GuiData->Selection.srSelection.Left, GuiData->Selection.srSelection.Left,
GuiData->Selection.srSelection.Top, GuiData->Selection.srSelection.Top,

View file

@ -57,12 +57,11 @@ CopyBlock(PTEXTMODE_SCREEN_BUFFER Buffer,
Selection->Left, Selection->Top, Selection->Right, Selection->Bottom); Selection->Left, Selection->Top, Selection->Right, Selection->Bottom);
/* Prevent against empty blocks */ /* Prevent against empty blocks */
if (Selection == NULL) return; if ((Selection == NULL) || ConioIsRectEmpty(Selection))
if (Selection->Left > Selection->Right || Selection->Top > Selection->Bottom)
return; return;
selWidth = Selection->Right - Selection->Left + 1; selWidth = ConioRectWidth(Selection);
selHeight = Selection->Bottom - Selection->Top + 1; selHeight = ConioRectHeight(Selection);
/* Basic size for one line... */ /* Basic size for one line... */
size = selWidth; size = selWidth;

View file

@ -29,9 +29,9 @@ do { \
(((Rect)->Left > (Rect)->Right) || ((Rect)->Top > (Rect)->Bottom)) (((Rect)->Left > (Rect)->Right) || ((Rect)->Top > (Rect)->Bottom))
#define ConioRectHeight(Rect) \ #define ConioRectHeight(Rect) \
(((Rect)->Top) > ((Rect)->Bottom) ? 0 : ((Rect)->Bottom) - ((Rect)->Top) + 1) (((Rect)->Top > (Rect)->Bottom) ? 0 : ((Rect)->Bottom - (Rect)->Top + 1))
#define ConioRectWidth(Rect) \ #define ConioRectWidth(Rect) \
(((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 1) (((Rect)->Left > (Rect)->Right) ? 0 : ((Rect)->Right - (Rect)->Left + 1))
static __inline BOOLEAN static __inline BOOLEAN