From: Sir Richard Date: Tue, 7 Sep 2010 07:50:51 +0000 (+0000) Subject: [GDI32]: Don't destroy the heap when calling GetSystemPaletteEntries. Note to whoever... X-Git-Tag: ReactOS-0.3.12~85 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=b96cb710f4b4aa2b28278241b09729e03586e622 [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. svn path=/trunk/; revision=48716 --- diff --git a/reactos/dll/win32/gdi32/objects/palette.c b/reactos/dll/win32/gdi32/objects/palette.c index 3f446576052..4301ac605ea 100644 --- a/reactos/dll/win32/gdi32/objects/palette.c +++ b/reactos/dll/win32/gdi32/objects/palette.c @@ -86,34 +86,36 @@ GetSystemPaletteEntries(HDC hDC, 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) - { - 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; + PALETTEENTRY ippe[256]; - if ( Index > cEntries ) Index = cEntries; - - RtlCopyMemory( ppe, - &ippe[iStartIndex], - Index*sizeof(PALETTEENTRY)); - } + if ((INT)cEntries >= 0) + { + if (GetDeviceCaps(hDC, RASTERCAPS) & RC_PALETTE) + { + return NtGdiDoPalette(hDC, + iStartIndex, + cEntries, + ppe, + GdiPalGetSystemEntries, + FALSE); + } + 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; + return 0; } UINT