From: Vadim Zeitlin Date: Fri, 5 Nov 2010 21:39:09 +0000 (+0000) Subject: Fix crash in wxColour ctor from NSColor in wxOSX/Cocoa. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/df7d93f67bae4a7598dc7058f90f35acb7bd584a Fix crash in wxColour ctor from NSColor in wxOSX/Cocoa. wxColour ctor from NSColor added by Kevin Ollivier in r62525 never worked as it passed NULL pointer to NSColor:getComponents and so always crashed. This resulted in a crash in the rich text editor of the text sample, for example. Fix this by passing a valid array containing colour components instead. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66030 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/osx/cocoa/colour.mm b/src/osx/cocoa/colour.mm index 55a305d29f..a59b71b2c0 100644 --- a/src/osx/cocoa/colour.mm +++ b/src/osx/cocoa/colour.mm @@ -23,14 +23,21 @@ wxColour::wxColour(WX_NSColor col) { size_t noComp = [col numberOfComponents]; - CGFloat *components = NULL; - if ( noComp >= 1 && noComp <= 4 ) + CGFloat components[4]; + CGFloat *p; + if ( noComp < 1 || noComp > WXSIZEOF(components) ) { // TODO verify whether we really are on a RGB color space m_alpha = wxALPHA_OPAQUE; [col getComponents: components]; + p = components; } - InitFromComponents(const_cast(components), noComp); + else // Unsupported colour format. + { + p = NULL; + } + + InitFromComponents(components, noComp); } WX_NSColor wxColour::OSXGetNSColor()