https://git.reactos.org/?p=reactos.git;a=commitdiff;h=570eba2a5283696e3228fb33a03b75b30b2a61ba

commit 570eba2a5283696e3228fb33a03b75b30b2a61ba
Author:     Hermès Bélusca-Maïto <[email protected]>
AuthorDate: Sat Feb 22 21:15:58 2020 +0100
Commit:     Hermès Bélusca-Maïto <[email protected]>
CommitDate: Sat Feb 22 21:15:58 2020 +0100

    [KERNEL32][CONSRV] Use more often the internal ConioRectHeight/Width() and 
ConioIsRectEmpty() macros.
---
 dll/win32/kernel32/client/console/readwrite.c       | 10 ++++------
 win32ss/user/winsrv/consrv/condrv/text.c            | 15 +++++++--------
 win32ss/user/winsrv/consrv/conoutput.c              |  8 ++++----
 win32ss/user/winsrv/consrv/frontends/gui/graphics.c |  4 ++--
 win32ss/user/winsrv/consrv/frontends/gui/text.c     |  7 +++----
 win32ss/user/winsrv/consrv/include/rect.h           |  4 ++--
 6 files changed, 22 insertions(+), 26 deletions(-)

diff --git a/dll/win32/kernel32/client/console/readwrite.c 
b/dll/win32/kernel32/client/console/readwrite.c
index c10d833bec1..b06f7ab8299 100644
--- a/dll/win32/kernel32/client/console/readwrite.c
+++ b/dll/win32/kernel32/client/console/readwrite.c
@@ -20,9 +20,9 @@
 
 /* See consrv/include/rect.h */
 #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) \
-    (((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 
1)
+    (((Rect)->Left > (Rect)->Right) ? 0 : ((Rect)->Right - (Rect)->Left + 1))
 
 
 /* PRIVATE FUNCTIONS 
**********************************************************/
@@ -436,8 +436,7 @@ IntReadConsoleOutput(IN HANDLE hConsoleOutput,
 
             /* Copy into the buffer */
 
-            SizeX = ReadOutputRequest->ReadRegion.Right -
-                    ReadOutputRequest->ReadRegion.Left + 1;
+            SizeX = ConioRectWidth(&ReadOutputRequest->ReadRegion);
 
             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 */
 
-        SizeX = WriteOutputRequest->WriteRegion.Right -
-                WriteOutputRequest->WriteRegion.Left + 1;
+        SizeX = ConioRectWidth(&WriteOutputRequest->WriteRegion);
 
         for (y = 0, Y = WriteOutputRequest->WriteRegion.Top; Y <= 
WriteOutputRequest->WriteRegion.Bottom; ++y, ++Y)
         {
diff --git a/win32ss/user/winsrv/consrv/condrv/text.c 
b/win32ss/user/winsrv/consrv/condrv/text.c
index 7108fcfdcc9..33abb74b642 100644
--- a/win32ss/user/winsrv/consrv/condrv/text.c
+++ b/win32ss/user/winsrv/consrv/condrv/text.c
@@ -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
      * '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
      * corrected for, and the window rectangle coordinates are shifted 
accordingly.
      */
-    if ((CapturedWindowRect.Right  < CapturedWindowRect.Left) ||
-        (CapturedWindowRect.Bottom < CapturedWindowRect.Top))
+    if (ConioIsRectEmpty(&CapturedWindowRect))
     {
         return STATUS_INVALID_PARAMETER;
     }
@@ -1627,8 +1626,8 @@ ConDrvSetConsoleWindowInfo(IN PCONSOLE Console,
     TermGetLargestConsoleWindowSize(Console, &LargestWindowSize);
     LargestWindowSize.X = min(LargestWindowSize.X, Buffer->ScreenBufferSize.X);
     LargestWindowSize.Y = min(LargestWindowSize.Y, Buffer->ScreenBufferSize.Y);
-    if ((CapturedWindowRect.Right - CapturedWindowRect.Left + 1 > 
LargestWindowSize.X) ||
-        (CapturedWindowRect.Bottom - CapturedWindowRect.Top + 1 > 
LargestWindowSize.Y))
+    if ((ConioRectWidth(&CapturedWindowRect)  > LargestWindowSize.X) ||
+        (ConioRectHeight(&CapturedWindowRect) > LargestWindowSize.Y))
     {
         return STATUS_INVALID_PARAMETER;
     }
@@ -1652,8 +1651,8 @@ ConDrvSetConsoleWindowInfo(IN PCONSOLE Console,
     Buffer->ViewOrigin.X = CapturedWindowRect.Left;
     Buffer->ViewOrigin.Y = CapturedWindowRect.Top;
 
-    Buffer->ViewSize.X = CapturedWindowRect.Right - CapturedWindowRect.Left + 
1;
-    Buffer->ViewSize.Y = CapturedWindowRect.Bottom - CapturedWindowRect.Top + 
1;
+    Buffer->ViewSize.X = ConioRectWidth(&CapturedWindowRect);
+    Buffer->ViewSize.Y = ConioRectHeight(&CapturedWindowRect);
 
     TermResizeTerminal(Console);
 
diff --git a/win32ss/user/winsrv/consrv/conoutput.c 
b/win32ss/user/winsrv/consrv/conoutput.c
index 0f8bc2bd3d3..079d781514c 100644
--- a/win32ss/user/winsrv/consrv/conoutput.c
+++ b/win32ss/user/winsrv/consrv/conoutput.c
@@ -497,8 +497,8 @@ CSR_API(SrvReadConsoleOutput)
 
     DPRINT("SrvReadConsoleOutput\n");
 
-    NumCells = (ReadOutputRequest->ReadRegion.Right - 
ReadOutputRequest->ReadRegion.Left + 1) *
-               (ReadOutputRequest->ReadRegion.Bottom - 
ReadOutputRequest->ReadRegion.Top + 1);
+    NumCells = ConioRectWidth(&ReadOutputRequest->ReadRegion) *
+               ConioRectHeight(&ReadOutputRequest->ReadRegion);
 
     /*
      * For optimization purposes, Windows (and hence ReactOS, too, for
@@ -562,8 +562,8 @@ CSR_API(SrvWriteConsoleOutput)
 
     DPRINT("SrvWriteConsoleOutput\n");
 
-    NumCells = (WriteOutputRequest->WriteRegion.Right - 
WriteOutputRequest->WriteRegion.Left + 1) *
-               (WriteOutputRequest->WriteRegion.Bottom - 
WriteOutputRequest->WriteRegion.Top + 1);
+    NumCells = ConioRectWidth(&WriteOutputRequest->WriteRegion) *
+               ConioRectHeight(&WriteOutputRequest->WriteRegion);
 
     Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(Process),
                                      WriteOutputRequest->OutputHandle,
diff --git a/win32ss/user/winsrv/consrv/frontends/gui/graphics.c 
b/win32ss/user/winsrv/consrv/frontends/gui/graphics.c
index ab0bc69a28f..63fd616059d 100644
--- a/win32ss/user/winsrv/consrv/frontends/gui/graphics.c
+++ b/win32ss/user/winsrv/consrv/frontends/gui/graphics.c
@@ -32,8 +32,8 @@ GuiCopyFromGraphicsBuffer(PGRAPHICS_SCREEN_BUFFER Buffer,
 
     if (Buffer->BitMap == NULL) return;
 
-    selWidth  = GuiData->Selection.srSelection.Right - 
GuiData->Selection.srSelection.Left + 1;
-    selHeight = GuiData->Selection.srSelection.Bottom - 
GuiData->Selection.srSelection.Top + 1;
+    selWidth  = ConioRectWidth(&GuiData->Selection.srSelection);
+    selHeight = ConioRectHeight(&GuiData->Selection.srSelection);
     DPRINT("Selection is (%d|%d) to (%d|%d)\n",
            GuiData->Selection.srSelection.Left,
            GuiData->Selection.srSelection.Top,
diff --git a/win32ss/user/winsrv/consrv/frontends/gui/text.c 
b/win32ss/user/winsrv/consrv/frontends/gui/text.c
index 0397be7d82e..fcbcbaf94e5 100644
--- a/win32ss/user/winsrv/consrv/frontends/gui/text.c
+++ b/win32ss/user/winsrv/consrv/frontends/gui/text.c
@@ -57,12 +57,11 @@ CopyBlock(PTEXTMODE_SCREEN_BUFFER Buffer,
            Selection->Left, Selection->Top, Selection->Right, 
Selection->Bottom);
 
     /* Prevent against empty blocks */
-    if (Selection == NULL) return;
-    if (Selection->Left > Selection->Right || Selection->Top > 
Selection->Bottom)
+    if ((Selection == NULL) || ConioIsRectEmpty(Selection))
         return;
 
-    selWidth  = Selection->Right - Selection->Left + 1;
-    selHeight = Selection->Bottom - Selection->Top + 1;
+    selWidth  = ConioRectWidth(Selection);
+    selHeight = ConioRectHeight(Selection);
 
     /* Basic size for one line... */
     size = selWidth;
diff --git a/win32ss/user/winsrv/consrv/include/rect.h 
b/win32ss/user/winsrv/consrv/include/rect.h
index 97859356cea..9ab56510216 100644
--- a/win32ss/user/winsrv/consrv/include/rect.h
+++ b/win32ss/user/winsrv/consrv/include/rect.h
@@ -29,9 +29,9 @@ do {    \
     (((Rect)->Left > (Rect)->Right) || ((Rect)->Top > (Rect)->Bottom))
 
 #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) \
-    (((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 
1)
+    (((Rect)->Left > (Rect)->Right) ? 0 : ((Rect)->Right - (Rect)->Left + 1))
 
 
 static __inline BOOLEAN

Reply via email to