[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 514147776a

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.
This commit is contained in:
Joachim Henze 2021-06-23 19:59:42 +02:00
parent c8ce0cc434
commit c596fd3ef6

View file

@ -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