From: Yoonsang Lee Date: Wed, 10 Jun 2015 08:29:13 +0000 (+0900) Subject: Fix prevent issue - pixbuf might be NULL X-Git-Tag: submit/tizen/20150623.063339~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=351a2acda78143a3485a2fbb260d8f0d25f964b9;p=platform%2Fcore%2Fuifw%2Fdali-core.git Fix prevent issue - pixbuf might be NULL - GetBuffer() might return null, so move pixbuf dereferencing code into the null checked block 2. returned_null: GetBuffer returns null. [show details] 3. var_assigned: Assigning: pixbuf = null return value from GetBuffer. 225 PixelBuffer* pixbuf = imageData->GetBuffer(); CID 402177 (#1 of 1): Dereference null return value (NULL_RETURNS) 7. dereference: Dereferencing a pointer that might be null pixbuf when calling memset. [Note: The source code implementation of the function has been overridden by a builtin model.] 253 memset( pixbuf, a, numPixels ); Change-Id: Ia35e1cb4ea2f04eac6dccbb4b8935b2c54905062 --- diff --git a/dali/internal/event/images/atlas-impl.cpp b/dali/internal/event/images/atlas-impl.cpp index 1f05a8f28..d1ebad902 100644 --- a/dali/internal/event/images/atlas-impl.cpp +++ b/dali/internal/event/images/atlas-impl.cpp @@ -224,33 +224,36 @@ void Atlas::ClearBackground(const Vector4& color ) BufferImagePtr imageData = BufferImage::New( mWidth, mHeight, mPixelFormat ); PixelBuffer* pixbuf = imageData->GetBuffer(); - // converting color value from float 0.f~1.f to byte 0~255 - unsigned char r = static_cast( 255.f * Clamp( color.r, 0.f, 1.f ) ); - unsigned char g = static_cast( 255.f * Clamp( color.g, 0.f, 1.f ) ); - unsigned char b = static_cast( 255.f * Clamp( color.b, 0.f, 1.f ) ); - unsigned char a = static_cast( 255.f * Clamp( color.a, 0.f, 1.f ) ); - if( mPixelFormat == Pixel::RGBA8888 ) + if( pixbuf ) { - // For little-endian byte order, the RGBA channels needs to be reversed for bit shifting. - uint32_t clearColor = ( (uint32_t) a<<24 | (uint32_t)b << 16 | (uint32_t)g << 8 | (uint32_t)r ); - uint32_t* buf = (uint32_t *) pixbuf; - for( unsigned int i = 0; i < numPixels; ++i ) + // converting color value from float 0.f~1.f to byte 0~255 + unsigned char r = static_cast( 255.f * Clamp( color.r, 0.f, 1.f ) ); + unsigned char g = static_cast( 255.f * Clamp( color.g, 0.f, 1.f ) ); + unsigned char b = static_cast( 255.f * Clamp( color.b, 0.f, 1.f ) ); + unsigned char a = static_cast( 255.f * Clamp( color.a, 0.f, 1.f ) ); + if( mPixelFormat == Pixel::RGBA8888 ) { - buf[i] = clearColor; + // For little-endian byte order, the RGBA channels needs to be reversed for bit shifting. + uint32_t clearColor = ( (uint32_t) a<<24 | (uint32_t)b << 16 | (uint32_t)g << 8 | (uint32_t)r ); + uint32_t* buf = (uint32_t *) pixbuf; + for( unsigned int i = 0; i < numPixels; ++i ) + { + buf[i] = clearColor; + } } - } - else if( mPixelFormat == Pixel::RGB888 ) - { - for( unsigned int i = 0; i < numPixels; ++i ) + else if( mPixelFormat == Pixel::RGB888 ) { - pixbuf[i*bytesPerPixel] = r; - pixbuf[i*bytesPerPixel+1] = g; - pixbuf[i*bytesPerPixel+2] = b; + for( unsigned int i = 0; i < numPixels; ++i ) + { + pixbuf[i*bytesPerPixel] = r; + pixbuf[i*bytesPerPixel+1] = g; + pixbuf[i*bytesPerPixel+2] = b; + } + } + else if( mPixelFormat == Pixel::A8 ) + { + memset( pixbuf, a, numPixels ); } - } - else if( mPixelFormat == Pixel::A8 ) - { - memset( pixbuf, a, numPixels ); } RectArea area;