https://git.reactos.org/?p=reactos.git;a=commitdiff;h=c596fd3ef6933c9eec95a…
commit c596fd3ef6933c9eec95a47c807d01d3776bbcc0
Author: Joachim Henze <Joachim.Henze(a)reactos.org>
AuthorDate: Wed Jun 23 19:59:42 2021 +0200
Commit: Joachim Henze <Joachim.Henze(a)reactos.org>
CommitDate: Wed Jun 23 19:59:42 2021 +0200
[WIN32K] CreateDIBPalette SEH Simplification #3758 CORE-17626
Enter an SEH2_TRY one time and do all testing within it instead of entering the SEH_TRY multiple times.
The commit is an addendum to 0.4.15-dev-2734-g 514147776a7e70636911033ab6c89779b2c8ee1e
Thanks to patches author Doug-Lyons
This is 1:1 the final approved content of #3758, but I committed
by hand and closed the PR to avoid squash+rebase.
---
win32ss/gdi/ntgdi/dibobj.c | 41 +++++++++++++++++------------------------
1 file changed, 17 insertions(+), 24 deletions(-)
diff --git a/win32ss/gdi/ntgdi/dibobj.c b/win32ss/gdi/ntgdi/dibobj.c
index 1ae6e8affa9..acd8da28d23 100644
--- a/win32ss/gdi/ntgdi/dibobj.c
+++ b/win32ss/gdi/ntgdi/dibobj.c
@@ -45,8 +45,6 @@ CreateDIBPalette(
{
PPALETTE ppal;
ULONG i, cBitsPixel, cColors;
- RGBQUAD rgb;
- NTSTATUS Status;
if (pbmi->bmiHeader.biSize < sizeof(BITMAPINFOHEADER))
{
@@ -129,34 +127,29 @@ CreateDIBPalette(
{
/* The colors are an array of RGBQUAD values */
RGBQUAD *prgb = (RGBQUAD*)((PCHAR)pbmi + pbmi->bmiHeader.biSize);
+ RGBQUAD colors[256] = {0};
// FIXME: do we need to handle PALETTEINDEX / PALETTERGB macro?
- /* Loop all color indices in the DIB */
- for (i = 0; i < cColors; i++)
+ /* Use SEH to verify we can READ prgb[] succesfully */
+ _SEH2_TRY
{
- /* User SEH to verify READ success */
- Status = STATUS_SUCCESS;
- _SEH2_TRY
- {
- rgb = prgb[i];
- }
- _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
- {
- Status = _SEH2_GetExceptionCode();
- /* On Read Failure, put zero in Palette */
- PALETTE_vSetRGBColorForIndex(ppal, i, 0);
- }
- _SEH2_END
+ RtlCopyMemory(colors, prgb, cColors * sizeof(colors[0]));
+ }
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ {
+ /* Do Nothing */
+ }
+ _SEH2_END;
- if(NT_SUCCESS(Status))
- {
- /* Get the color value and translate it to a COLORREF */
- COLORREF crColor = RGB(rgb.rgbRed, rgb.rgbGreen, rgb.rgbBlue);
+ for (i = 0; i < cColors; ++i)
+ {
+ /* Get the color value and translate it to a COLORREF */
+ COLORREF crColor = RGB(colors[i].rgbRed, colors[i].rgbGreen, colors[i].rgbBlue);
+
+ /* Set the RGB value in the palette */
+ PALETTE_vSetRGBColorForIndex(ppal, i, crColor);
- /* Set the RGB value in the palette */
- PALETTE_vSetRGBColorForIndex(ppal, i, crColor);
- }
}
}
else