Author: sir_richard
Date: Tue Sep 7 07:50:51 2010
New Revision: 48716
URL:
http://svn.reactos.org/svn/reactos?rev=48716&view=rev
Log:
[GDI32]: Don't destroy the heap when calling GetSystemPaletteEntries. Note to whoever
wrote "//make this work": (&array[x]) is defintely not equal to (&array
+ x). This is why we don't use pointers-to-arrays, among other reasons.
[GDI32]: Reformat GetSystemPaletteEntries away from grotesque 5-space identation (who does
that?).
[GDI32]: Optimize GetSystemPaletteEntries by not zeroing over fields that get overwritten
anyway.
[GDI32]: Simplify loop control, remove not-needed local variable in
GetSystemPaletteEntries.
Modified:
trunk/reactos/dll/win32/gdi32/objects/palette.c
Modified: trunk/reactos/dll/win32/gdi32/objects/palette.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/gdi32/objects/pa…
==============================================================================
--- trunk/reactos/dll/win32/gdi32/objects/palette.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/gdi32/objects/palette.c [iso-8859-1] Tue Sep 7 07:50:51 2010
@@ -86,34 +86,36 @@
UINT cEntries,
LPPALETTEENTRY ppe)
{
- PALETTEENTRY ippe[256];
- // Make this work!
- if ((INT)cEntries < 0 ) return 0;
-
- if ( GetDeviceCaps(hDC, RASTERCAPS) & RC_PALETTE )
- return NtGdiDoPalette(hDC, iStartIndex, cEntries, ppe, GdiPalGetSystemEntries,
FALSE);
- else
- {
- if (ppe)
+ PALETTEENTRY ippe[256];
+
+ if ((INT)cEntries >= 0)
+ {
+ if (GetDeviceCaps(hDC, RASTERCAPS) & RC_PALETTE)
{
- RtlZeroMemory( &ippe, sizeof(ippe) );
- RtlCopyMemory( &ippe, &sys_pal_template, 10 * sizeof(PALETTEENTRY) );
- RtlCopyMemory( &ippe + 246 , &sys_pal_template + 10 , 10 *
sizeof(PALETTEENTRY) );
-
- if (iStartIndex < 256)
- {
- UINT Index = 256 - iStartIndex;
-
- if ( Index > cEntries ) Index = cEntries;
-
- RtlCopyMemory( ppe,
- &ippe[iStartIndex],
- Index*sizeof(PALETTEENTRY));
- }
+ return NtGdiDoPalette(hDC,
+ iStartIndex,
+ cEntries,
+ ppe,
+ GdiPalGetSystemEntries,
+ FALSE);
}
- }
-
- return 0;
+ else if (ppe)
+ {
+ RtlCopyMemory(ippe, sys_pal_template, 10 * sizeof(PALETTEENTRY));
+ RtlCopyMemory(&ippe[246], &sys_pal_template[10], 10 *
sizeof(PALETTEENTRY));
+ RtlZeroMemory(&ippe[10], sizeof(ippe) - 20 * sizeof(PALETTEENTRY));
+
+ if (iStartIndex < 256)
+ {
+ RtlCopyMemory(ppe,
+ &ippe[iStartIndex],
+ min(256 - iStartIndex, cEntries) *
+ sizeof(PALETTEENTRY));
+ }
+ }
+ }
+
+ return 0;
}
UINT