Fix buffer overrun in Linux/x86_64 (Pixel is a 64 bit long, passing
a 32 bit int pointer to XtVaGetValues will cause trouble). Using a long should suffice. A configure test would be better. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41640 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -2767,6 +2767,7 @@ typedef void* WXFontType; /* either a XmFontList or XmRenderTable */
|
||||
typedef void* WXString;
|
||||
|
||||
typedef unsigned long Atom; /* this might fail on a few architectures */
|
||||
typedef long WXPixel; /* safety catch in src/motif/colour.cpp */
|
||||
|
||||
#endif /* Motif */
|
||||
|
||||
|
@@ -41,8 +41,8 @@ public:
|
||||
unsigned char Green() const { return m_green; }
|
||||
unsigned char Blue() const { return m_blue; }
|
||||
|
||||
int GetPixel() const { return m_pixel; };
|
||||
void SetPixel(int pixel) { m_pixel = pixel; m_isInit = true; };
|
||||
WXPixel GetPixel() const { return m_pixel; };
|
||||
void SetPixel(WXPixel pixel) { m_pixel = pixel; m_isInit = true; };
|
||||
|
||||
inline bool operator == (const wxColour& colour) const { return (m_red == colour.m_red && m_green == colour.m_green && m_blue == colour.m_blue); }
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
// TODO: can this handle mono displays? If not, we should have an extra
|
||||
// flag to specify whether this should be black or white by default.
|
||||
|
||||
int AllocColour(WXDisplay* display, bool realloc = false);
|
||||
WXPixel AllocColour(WXDisplay* display, bool realloc = false);
|
||||
|
||||
protected:
|
||||
// Helper function
|
||||
@@ -72,7 +72,7 @@ private:
|
||||
unsigned char m_green;
|
||||
|
||||
public:
|
||||
int m_pixel;
|
||||
WXPixel m_pixel;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -92,11 +92,11 @@ protected:
|
||||
// if roundToWhite == true then the colour will be set to white unless
|
||||
// it is RGB 0x000000;if roundToWhite == true the colour wull be set to
|
||||
// black unless it id RGB 0xffffff
|
||||
int CalculatePixel(wxColour& colour, wxColour& curCol,
|
||||
WXPixel CalculatePixel(wxColour& colour, wxColour& curCol,
|
||||
bool roundToWhite) const;
|
||||
// sets the foreground pixel taking into account the
|
||||
// currently selected logical operation
|
||||
void SetForegroundPixelWithLogicalFunction(int pixel);
|
||||
void SetForegroundPixelWithLogicalFunction(WXPixel pixel);
|
||||
|
||||
virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
|
||||
int style = wxFLOOD_SURFACE);
|
||||
@@ -153,7 +153,7 @@ protected:
|
||||
WXRegion m_clipRegion;
|
||||
|
||||
// Not sure if we'll need all of these
|
||||
int m_backgroundPixel;
|
||||
WXPixel m_backgroundPixel;
|
||||
wxColour m_currentColour;
|
||||
int m_currentPenWidth ;
|
||||
int m_currentPenJoin ;
|
||||
|
@@ -38,7 +38,7 @@ class WXDLLIMPEXP_CORE wxRegion;
|
||||
extern int wxCharCodeXToWX(KeySym keySym);
|
||||
extern KeySym wxCharCodeWXToX(int id);
|
||||
|
||||
int wxGetBestMatchingPixel(Display *display, XColor *desiredColor, Colormap cmap);
|
||||
WXPixel wxGetBestMatchingPixel(Display *display, XColor *desiredColor, Colormap cmap);
|
||||
Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap );
|
||||
|
||||
extern XColor g_itemColors[];
|
||||
|
@@ -152,7 +152,7 @@ void wxBitmapButton::DoSetBitmap()
|
||||
// in the current widget background colour.
|
||||
if (m_bmpNormalOriginal.GetMask())
|
||||
{
|
||||
int backgroundPixel;
|
||||
WXPixel backgroundPixel;
|
||||
XtVaGetValues((Widget) m_mainWidget,
|
||||
XmNbackground, &backgroundPixel,
|
||||
NULL);
|
||||
@@ -177,7 +177,7 @@ void wxBitmapButton::DoSetBitmap()
|
||||
{
|
||||
if (m_bmpDisabledOriginal.GetMask())
|
||||
{
|
||||
int backgroundPixel;
|
||||
WXPixel backgroundPixel;
|
||||
XtVaGetValues((Widget) m_mainWidget,
|
||||
XmNbackground, &backgroundPixel,
|
||||
NULL);
|
||||
@@ -202,7 +202,7 @@ void wxBitmapButton::DoSetBitmap()
|
||||
{
|
||||
if (m_bmpSelectedOriginal.GetMask())
|
||||
{
|
||||
int backgroundPixel;
|
||||
WXPixel backgroundPixel;
|
||||
XtVaGetValues((Widget) m_mainWidget,
|
||||
XmNarmColor, &backgroundPixel,
|
||||
NULL);
|
||||
|
@@ -125,7 +125,7 @@ WXPixmap wxBitmapCache::GetPixmapFromCache(WXWidget w)
|
||||
while( XmIsGadget( widget ) )
|
||||
widget = XtParent( widget );
|
||||
|
||||
Pixel fg, bg;
|
||||
WXPixel fg, bg;
|
||||
XtVaGetValues( widget,
|
||||
XmNbackground, &bg,
|
||||
XmNforeground, &fg,
|
||||
|
@@ -155,7 +155,7 @@ void wxCheckBox::ChangeBackgroundColour()
|
||||
NULL);
|
||||
|
||||
wxColour colour = *wxBLACK;
|
||||
int selectPixel = colour.AllocColour(XtDisplay((Widget)m_mainWidget));
|
||||
WXPixel selectPixel = colour.AllocColour(XtDisplay((Widget)m_mainWidget));
|
||||
|
||||
// Better to have the checkbox selection in black, or it's
|
||||
// hard to determine what state it is in.
|
||||
|
@@ -34,14 +34,14 @@
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
|
||||
|
||||
wxCOMPILE_TIME_ASSERT( sizeof(WXPixel) == sizeof(Pixel), PixelSizeIsOk );
|
||||
|
||||
// Colour
|
||||
|
||||
void wxColour::Init()
|
||||
{
|
||||
m_isInit = false;
|
||||
m_red =
|
||||
m_blue =
|
||||
m_green = 0;
|
||||
m_red = m_blue = m_green = 0;
|
||||
m_pixel = -1;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ void wxColour::InitRGBA(unsigned char r, unsigned char g, unsigned char b,
|
||||
// TODO: can this handle mono displays? If not, we should have an extra
|
||||
// flag to specify whether this should be black or white by default.
|
||||
|
||||
int wxColour::AllocColour(WXDisplay* display, bool realloc)
|
||||
WXPixel wxColour::AllocColour(WXDisplay* display, bool realloc)
|
||||
{
|
||||
if ((m_pixel != -1) && !realloc)
|
||||
return m_pixel;
|
||||
@@ -106,7 +106,7 @@ int wxColour::AllocColour(WXDisplay* display, bool realloc)
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pixel = (int) color.pixel;
|
||||
m_pixel = (WXPixel) color.pixel;
|
||||
return m_pixel;
|
||||
}
|
||||
}
|
||||
@@ -141,14 +141,14 @@ A read-only colour will not change.
|
||||
may give better matching.
|
||||
-------------------------------------------*/
|
||||
|
||||
int wxGetBestMatchingPixel(Display *display, XColor *desiredColor, Colormap cmap)
|
||||
WXPixel wxGetBestMatchingPixel(Display *display, XColor *desiredColor, Colormap cmap)
|
||||
{
|
||||
if (cmap == (Colormap) NULL)
|
||||
cmap = (Colormap) wxTheApp->GetMainColormap(display);
|
||||
|
||||
int numPixVals = XDisplayCells(display, DefaultScreen (display));
|
||||
int mindist = 256 * 256 * 3;
|
||||
int bestpixel = (int) BlackPixel (display, DefaultScreen (display));
|
||||
Pixel bestpixel = BlackPixel (display, DefaultScreen (display));
|
||||
int red = desiredColor->red >> 8;
|
||||
int green = desiredColor->green >> 8;
|
||||
int blue = desiredColor->blue >> 8;
|
||||
|
@@ -195,7 +195,7 @@ wxWindowDC::wxWindowDC( wxWindow *window )
|
||||
&gcvalues);
|
||||
}
|
||||
|
||||
m_backgroundPixel = (int) gcvalues.background;
|
||||
m_backgroundPixel = gcvalues.background;
|
||||
|
||||
SetBackground(wxBrush(m_window->GetBackgroundColour(), wxSOLID));
|
||||
}
|
||||
@@ -797,13 +797,13 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest,
|
||||
// foreground colour. [m_textForegroundColour] Background pixels (0)
|
||||
// will be painted with backgound colour (m_textBackgroundColour)
|
||||
// Using ::SetPen is horribly slow, so avoid doing it
|
||||
int oldBackgroundPixel = -1;
|
||||
int oldForegroundPixel = -1;
|
||||
WXPixel oldBackgroundPixel = -1;
|
||||
WXPixel oldForegroundPixel = -1;
|
||||
|
||||
if (m_textBackgroundColour.Ok())
|
||||
{
|
||||
oldBackgroundPixel = m_backgroundPixel;
|
||||
int pixel = m_textBackgroundColour.AllocColour(m_display);
|
||||
WXPixel pixel = m_textBackgroundColour.AllocColour(m_display);
|
||||
|
||||
XSetBackground ((Display*) m_display, (GC) m_gc, pixel);
|
||||
if (m_window && m_window->GetBackingPixmap())
|
||||
@@ -818,7 +818,7 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest,
|
||||
CalculatePixel( m_textForegroundColour,
|
||||
m_textForegroundColour, true);
|
||||
|
||||
int pixel = m_textForegroundColour.GetPixel();
|
||||
WXPixel pixel = m_textForegroundColour.GetPixel();
|
||||
if (pixel > -1)
|
||||
SetForegroundPixelWithLogicalFunction(pixel);
|
||||
}
|
||||
@@ -1056,7 +1056,7 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
|
||||
|
||||
if (!sameColour || !GET_OPTIMIZATION)
|
||||
{
|
||||
int pixel = m_textBackgroundColour.AllocColour(m_display);
|
||||
WXPixel pixel = m_textBackgroundColour.AllocColour(m_display);
|
||||
m_currentColour = m_textBackgroundColour;
|
||||
|
||||
// Set the GC to the required colour
|
||||
@@ -1089,7 +1089,7 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
|
||||
|
||||
if (!sameColour || !GET_OPTIMIZATION)
|
||||
{
|
||||
int pixel = CalculatePixel(m_textForegroundColour,
|
||||
WXPixel pixel = CalculatePixel(m_textForegroundColour,
|
||||
m_currentColour, false);
|
||||
|
||||
// Set the GC to the required colour
|
||||
@@ -1161,10 +1161,10 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y,
|
||||
|
||||
wxCHECK_RET( Ok(), "invalid dc" );
|
||||
|
||||
int oldBackgroundPixel = -1;
|
||||
int oldForegroundPixel = -1;
|
||||
int foregroundPixel = -1;
|
||||
int backgroundPixel = -1;
|
||||
WXPixel oldBackgroundPixel = -1;
|
||||
WXPixel oldForegroundPixel = -1;
|
||||
WXPixel foregroundPixel = -1;
|
||||
WXPixel backgroundPixel = -1;
|
||||
|
||||
if (m_textBackgroundColour.Ok())
|
||||
{
|
||||
@@ -1414,7 +1414,7 @@ void wxWindowDC::SetFont( const wxFont &font )
|
||||
#endif
|
||||
}
|
||||
|
||||
void wxWindowDC::SetForegroundPixelWithLogicalFunction(int pixel)
|
||||
void wxWindowDC::SetForegroundPixelWithLogicalFunction(WXPixel pixel)
|
||||
{
|
||||
if (m_logicalFunction == wxXOR)
|
||||
{
|
||||
@@ -1434,12 +1434,12 @@ void wxWindowDC::SetForegroundPixelWithLogicalFunction(int pixel)
|
||||
}
|
||||
}
|
||||
|
||||
int wxWindowDC::CalculatePixel(wxColour& colour, wxColour& curCol,
|
||||
WXPixel wxWindowDC::CalculatePixel(wxColour& colour, wxColour& curCol,
|
||||
bool roundToWhite) const
|
||||
{
|
||||
const unsigned char wp = (unsigned char)255;
|
||||
|
||||
int pixel = -1;
|
||||
WXPixel pixel = -1;
|
||||
if(!m_colour) // Mono display
|
||||
{
|
||||
unsigned char red = colour.Red ();
|
||||
@@ -1451,7 +1451,7 @@ int wxWindowDC::CalculatePixel(wxColour& colour, wxColour& curCol,
|
||||
((red != 0 || blue != 0 || green != 0) && roundToWhite))
|
||||
{
|
||||
curCol = *wxWHITE;
|
||||
pixel = (int)WhitePixel((Display*) m_display,
|
||||
pixel = WhitePixel((Display*) m_display,
|
||||
DefaultScreen((Display*) m_display));
|
||||
curCol.SetPixel(pixel);
|
||||
colour.SetPixel(pixel);
|
||||
@@ -1459,7 +1459,7 @@ int wxWindowDC::CalculatePixel(wxColour& colour, wxColour& curCol,
|
||||
else
|
||||
{
|
||||
curCol = *wxBLACK;
|
||||
pixel = (int)BlackPixel((Display*) m_display,
|
||||
pixel = BlackPixel((Display*) m_display,
|
||||
DefaultScreen((Display*) m_display));
|
||||
curCol.SetPixel(pixel);
|
||||
colour.SetPixel(pixel);
|
||||
@@ -1717,7 +1717,7 @@ void wxWindowDC::SetPen( const wxPen &pen )
|
||||
if (!sameColour || !GET_OPTIMIZATION
|
||||
|| ((m_logicalFunction == wxXOR) || (m_autoSetting & 0x2)))
|
||||
{
|
||||
int pixel = -1;
|
||||
WXPixel pixel = -1;
|
||||
if (m_pen.GetStyle () == wxTRANSPARENT)
|
||||
pixel = m_backgroundPixel;
|
||||
else
|
||||
@@ -1884,7 +1884,7 @@ void wxWindowDC::SetBrush( const wxBrush &brush )
|
||||
// must test m_logicalFunction, because it involves background!
|
||||
if (!sameColour || !GET_OPTIMIZATION || m_logicalFunction == wxXOR)
|
||||
{
|
||||
int pixel = CalculatePixel(m_brush.GetColour(), m_currentColour, true);
|
||||
WXPixel pixel = CalculatePixel(m_brush.GetColour(), m_currentColour, true);
|
||||
|
||||
if (pixel > -1)
|
||||
SetForegroundPixelWithLogicalFunction(pixel);
|
||||
@@ -2172,7 +2172,7 @@ static void XCopyRemote(Display *src_display, Display *dest_display,
|
||||
static const int CACHE_SIZE = 256;
|
||||
|
||||
unsigned int i, j;
|
||||
unsigned long cachesrc[CACHE_SIZE], cachedest[CACHE_SIZE];
|
||||
Pixel cachesrc[CACHE_SIZE], cachedest[CACHE_SIZE];
|
||||
int k, cache_pos, all_cache;
|
||||
|
||||
if (!cache || !*cache)
|
||||
@@ -2190,7 +2190,7 @@ static void XCopyRemote(Display *src_display, Display *dest_display,
|
||||
|
||||
for (i = 0; i < w; i++)
|
||||
for (j = 0; j < h; j++) {
|
||||
unsigned long pixel;
|
||||
Pixel pixel;
|
||||
XColor xcol;
|
||||
|
||||
pixel = XGetPixel(image, i, j);
|
||||
|
@@ -52,7 +52,7 @@ wxMemoryDC::wxMemoryDC(void)
|
||||
GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCSubwindowMode,
|
||||
&gcvalues);
|
||||
|
||||
m_backgroundPixel = (int) gcvalues.background;
|
||||
m_backgroundPixel = gcvalues.background;
|
||||
|
||||
SetBrush (* wxWHITE_BRUSH);
|
||||
SetPen (* wxBLACK_PEN);
|
||||
@@ -79,7 +79,7 @@ wxMemoryDC::wxMemoryDC( wxDC* dc )
|
||||
GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCSubwindowMode,
|
||||
&gcvalues);
|
||||
|
||||
m_backgroundPixel = (int) gcvalues.background;
|
||||
m_backgroundPixel = gcvalues.background;
|
||||
|
||||
SetBrush (* wxWHITE_BRUSH);
|
||||
SetPen (* wxBLACK_PEN);
|
||||
@@ -112,7 +112,7 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
|
||||
GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCSubwindowMode,
|
||||
&gcvalues);
|
||||
|
||||
m_backgroundPixel = (int) gcvalues.background;
|
||||
m_backgroundPixel = gcvalues.background;
|
||||
m_ok = true;
|
||||
|
||||
SetBrush (* wxWHITE_BRUSH);
|
||||
|
@@ -61,7 +61,7 @@ wxScreenDC::wxScreenDC()
|
||||
GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCSubwindowMode,
|
||||
&gcvalues);
|
||||
|
||||
m_backgroundPixel = (int) gcvalues.background;
|
||||
m_backgroundPixel = gcvalues.background;
|
||||
m_ok = true;
|
||||
}
|
||||
|
||||
|
@@ -351,7 +351,7 @@ void wxRadioBox::ChangeBackgroundColour()
|
||||
wxWindow::ChangeBackgroundColour();
|
||||
|
||||
wxColour colour = *wxBLACK;
|
||||
int selectPixel = colour.AllocColour(XtDisplay((Widget)m_mainWidget));
|
||||
WXPixel selectPixel = colour.AllocColour(XtDisplay((Widget)m_mainWidget));
|
||||
|
||||
for (unsigned int i = 0; i < m_noItems; i++)
|
||||
{
|
||||
|
@@ -142,7 +142,7 @@ void wxRadioButton::ChangeBackgroundColour()
|
||||
|
||||
// What colour should this be?
|
||||
wxColour colour = *wxBLACK;
|
||||
int selectPixel = colour.AllocColour(XtDisplay((Widget)m_mainWidget));
|
||||
WXPixel selectPixel = colour.AllocColour(XtDisplay((Widget)m_mainWidget));
|
||||
|
||||
XtVaSetValues ((Widget) GetMainWidget(),
|
||||
XmNselectColor, selectPixel,
|
||||
|
@@ -96,7 +96,7 @@ void wxStaticBitmap::DoSetBitmap()
|
||||
// in the current widget background colour.
|
||||
if (m_messageBitmapOriginal.GetMask())
|
||||
{
|
||||
int backgroundPixel;
|
||||
WXPixel backgroundPixel;
|
||||
XtVaGetValues( widget, XmNbackground, &backgroundPixel,
|
||||
NULL);
|
||||
|
||||
|
@@ -379,7 +379,7 @@ bool wxToolBar::Realize()
|
||||
insensBmp = tool->GetDisabledBitmap();
|
||||
if ( bmp.GetMask() || insensBmp.GetMask() )
|
||||
{
|
||||
int backgroundPixel;
|
||||
WXPixel backgroundPixel;
|
||||
XtVaGetValues(button, XmNbackground, &backgroundPixel,
|
||||
NULL);
|
||||
|
||||
@@ -402,7 +402,7 @@ bool wxToolBar::Realize()
|
||||
// Create a selected/toggled bitmap. If there isn't a 2nd
|
||||
// bitmap, we need to create it (with a darker, selected
|
||||
// background)
|
||||
int backgroundPixel;
|
||||
WXPixel backgroundPixel;
|
||||
if ( tool->CanBeToggled() )
|
||||
XtVaGetValues(button, XmNselectColor, &backgroundPixel,
|
||||
NULL);
|
||||
|
Reference in New Issue
Block a user