From 96e9053d033666df7ebf696dc45c2c923d263b08 Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Mon, 4 Mar 2024 10:43:17 +0900 Subject: [PATCH] [Tizen] Fix svace phase 2 : Print error log when malloc failed Let we print error log if malloc failed. There was some codes that we assume malloc success always. This is not safe. So we have to add some guard codes for malloc failed cases. Change-Id: Ie2f3500258ba2c33a3df1adf492d56f3235048f1 Signed-off-by: Eunki, Hong --- .../text-abstraction/glyph-buffer-data.cpp | 6 ++- .../graphics/gles-impl/egl-graphics-controller.cpp | 13 +++-- .../graphics/gles-impl/gles-graphics-buffer.cpp | 16 ++++--- .../graphics/gles-impl/gles2-graphics-memory.cpp | 8 +++- dali/internal/imaging/common/gif-loading.cpp | 22 +++++++-- dali/internal/imaging/common/image-operations.cpp | 7 +++ dali/internal/imaging/common/loader-jpeg-turbo.cpp | 8 +++- dali/internal/imaging/common/loader-png.cpp | 4 +- dali/internal/imaging/common/pixel-buffer-impl.cpp | 13 +++++ dali/internal/imaging/common/webp-loading.cpp | 26 +++++----- .../bidirectional-support-impl.cpp | 19 ++++++-- .../text/text-abstraction/cairo-renderer.cpp | 4 ++ .../text/text-abstraction/hyphenation-impl.cpp | 8 +++- .../text/text-abstraction/plugin/embedded-item.cpp | 14 ++++-- .../plugin/font-client-plugin-impl.cpp | 6 +++ .../text-abstraction/plugin/font-client-utils.cpp | 8 +++- .../plugin/font-face-glyph-cache-manager.cpp | 55 ++++++++++++++++------ 17 files changed, 181 insertions(+), 56 deletions(-) diff --git a/dali/devel-api/text-abstraction/glyph-buffer-data.cpp b/dali/devel-api/text-abstraction/glyph-buffer-data.cpp index fec3884..39a3a34 100644 --- a/dali/devel-api/text-abstraction/glyph-buffer-data.cpp +++ b/dali/devel-api/text-abstraction/glyph-buffer-data.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -97,6 +97,7 @@ size_t GlyphBufferData::Compress(const uint8_t* const __restrict__ inBuffer, Gly compressedBuffer = (uint8_t*)malloc(bufferSize); if(DALI_UNLIKELY(compressedBuffer == nullptr)) { + DALI_LOG_ERROR("malloc is failed. request malloc size : %zu\n", bufferSize); return 0u; } outBufferData.isBufferOwned = true; @@ -116,6 +117,7 @@ size_t GlyphBufferData::Compress(const uint8_t* const __restrict__ inBuffer, Gly compressedBuffer = (uint8_t*)malloc(bufferSize); if(DALI_UNLIKELY(compressedBuffer == nullptr)) { + DALI_LOG_ERROR("malloc is failed. request malloc size : %zu\n", bufferSize); return 0u; } outBufferData.isBufferOwned = true; @@ -148,6 +150,7 @@ size_t GlyphBufferData::Compress(const uint8_t* const __restrict__ inBuffer, Gly uint8_t* __restrict__ tempBuffer = (uint8_t*)malloc(outBufferData.height * (widthByte + 1)); if(DALI_UNLIKELY(tempBuffer == nullptr)) { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u\n", outBufferData.height * (widthByte + 1)); return 0u; } @@ -294,6 +297,7 @@ size_t GlyphBufferData::Compress(const uint8_t* const __restrict__ inBuffer, Gly compressedBuffer = (uint8_t*)malloc(bufferSize); if(DALI_UNLIKELY(compressedBuffer == nullptr)) { + DALI_LOG_ERROR("malloc is failed. request malloc size : %zu\n", bufferSize); free(tempBuffer); return 0u; } diff --git a/dali/internal/graphics/gles-impl/egl-graphics-controller.cpp b/dali/internal/graphics/gles-impl/egl-graphics-controller.cpp index 2d81571..d0719f6 100644 --- a/dali/internal/graphics/gles-impl/egl-graphics-controller.cpp +++ b/dali/internal/graphics/gles-impl/egl-graphics-controller.cpp @@ -934,11 +934,18 @@ void EglGraphicsController::UpdateTextures(const std::vector& uint8_t* stagingBuffer = reinterpret_cast(malloc(info.srcSize)); - uint8_t* srcMemory = &reinterpret_cast(source.memorySource.memory)[info.srcOffset]; + if(DALI_UNLIKELY(stagingBuffer == nullptr)) + { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u\n", info.srcSize); + } + else + { + uint8_t* srcMemory = &reinterpret_cast(source.memorySource.memory)[info.srcOffset]; - std::copy(srcMemory, srcMemory + info.srcSize, stagingBuffer); + std::copy(srcMemory, srcMemory + info.srcSize, stagingBuffer); - mTextureUploadTotalCPUMemoryUsed += info.srcSize; + mTextureUploadTotalCPUMemoryUsed += info.srcSize; + } // store staging buffer source.memorySource.memory = stagingBuffer; diff --git a/dali/internal/graphics/gles-impl/gles-graphics-buffer.cpp b/dali/internal/graphics/gles-impl/gles-graphics-buffer.cpp index f41ca6c..d2fbaaf 100644 --- a/dali/internal/graphics/gles-impl/gles-graphics-buffer.cpp +++ b/dali/internal/graphics/gles-impl/gles-graphics-buffer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,11 +56,11 @@ bool Buffer::TryRecycle(const Graphics::BufferCreateInfo& createInfo, Graphics:: mSetForGLRecycling = false; // if different buffer spec, we need new buffer - if(!(createInfo.size == mCreateInfo.size - && createInfo.allocationCallbacks == mCreateInfo.allocationCallbacks - && createInfo.propertiesFlags == mCreateInfo.propertiesFlags - && createInfo.usage == mCreateInfo.usage - && createInfo.nextExtension == mCreateInfo.nextExtension )) + if(!(createInfo.size == mCreateInfo.size && + createInfo.allocationCallbacks == mCreateInfo.allocationCallbacks && + createInfo.propertiesFlags == mCreateInfo.propertiesFlags && + createInfo.usage == mCreateInfo.usage && + createInfo.nextExtension == mCreateInfo.nextExtension)) { return false; } @@ -116,6 +116,10 @@ void Buffer::InitializeCPUBuffer() else { mBufferPtr = malloc(mCreateInfo.size); + if(DALI_UNLIKELY(mBufferPtr == nullptr)) + { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u\n", mCreateInfo.size); + } } } diff --git a/dali/internal/graphics/gles-impl/gles2-graphics-memory.cpp b/dali/internal/graphics/gles-impl/gles2-graphics-memory.cpp index 92b4ef0..6ad22f8 100644 --- a/dali/internal/graphics/gles-impl/gles2-graphics-memory.cpp +++ b/dali/internal/graphics/gles-impl/gles2-graphics-memory.cpp @@ -63,8 +63,12 @@ void* Memory2::LockRegion(uint32_t offset, uint32_t size) } else { - auto retval = malloc(size); - mMappedPointer = retval; + auto retval = malloc(size); + mMappedPointer = retval; + if(DALI_UNLIKELY(mMappedPointer == nullptr)) + { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u\n", size); + } mIsAllocatedLocally = true; } } diff --git a/dali/internal/imaging/common/gif-loading.cpp b/dali/internal/imaging/common/gif-loading.cpp index 37d8109..c35899a 100644 --- a/dali/internal/imaging/common/gif-loading.cpp +++ b/dali/internal/imaging/common/gif-loading.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -315,8 +315,13 @@ bool LoaderInfo::FileData::LoadLocalFile() if(DALI_LIKELY(!fseek(fp, 0, SEEK_SET))) { - globalMap = reinterpret_cast(malloc(sizeof(GifByteType) * length)); - length = fread(globalMap, sizeof(GifByteType), length, fp); + globalMap = reinterpret_cast(malloc(sizeof(GifByteType) * static_cast(length))); + if(DALI_UNLIKELY(globalMap == nullptr)) + { + DALI_LOG_ERROR("malloc is failed. request malloc size : %llu\n", sizeof(GifByteType) * static_cast(length)); + return false; + } + length = fread(globalMap, sizeof(GifByteType), length, fp); } else { @@ -346,8 +351,15 @@ bool LoaderInfo::FileData::LoadRemoteFile() if(DALI_LIKELY(!fseek(fp, 0, SEEK_SET))) { globalMap = reinterpret_cast(malloc(sizeof(GifByteType) * blobSize)); - length = fread(globalMap, sizeof(GifByteType), blobSize, fp); - succeeded = true; + if(DALI_UNLIKELY(globalMap == nullptr)) + { + DALI_LOG_ERROR("malloc is failed. request malloc size : %zu\n", sizeof(GifByteType) * blobSize); + } + else + { + length = fread(globalMap, sizeof(GifByteType), blobSize, fp); + succeeded = true; + } } else { diff --git a/dali/internal/imaging/common/image-operations.cpp b/dali/internal/imaging/common/image-operations.cpp index f4863ab..93b23dd 100644 --- a/dali/internal/imaging/common/image-operations.cpp +++ b/dali/internal/imaging/common/image-operations.cpp @@ -529,6 +529,7 @@ bool Rotate90(const uint8_t* const pixelsIn, pixelsOut = static_cast(malloc(widthOut * heightOut * pixelSize)); if(nullptr == pixelsOut) { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u x %u x %u\n", widthOut, heightOut, pixelSize); widthOut = 0u; heightOut = 0u; @@ -587,6 +588,7 @@ bool Rotate180(const uint8_t* const pixelsIn, pixelsOut = static_cast(malloc(widthIn * heightIn * pixelSize)); if(nullptr == pixelsOut) { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u x %u x %u\n", widthIn, heightIn, pixelSize); // Return if the memory allocations fails. return false; } @@ -650,6 +652,7 @@ bool Rotate270(const uint8_t* const pixelsIn, pixelsOut = static_cast(malloc(widthOut * heightOut * pixelSize)); if(nullptr == pixelsOut) { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u x %u x %u\n", widthOut, heightOut, pixelSize); widthOut = 0u; heightOut = 0u; @@ -2557,6 +2560,7 @@ void RotateByShear(const uint8_t* const pixelsIn, if(nullptr == pixelsOut) { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u x %u x %u\n", widthOut, heightOut, pixelSize); widthOut = 0u; heightOut = 0u; @@ -2595,6 +2599,7 @@ void RotateByShear(const uint8_t* const pixelsIn, if(nullptr == pixelsOut) { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u x %u x %u\n", widthOut, heightOut, pixelSize); widthOut = 0u; heightOut = 0u; @@ -2632,6 +2637,7 @@ void RotateByShear(const uint8_t* const pixelsIn, if(nullptr == pixelsOut) { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u x %u x %u\n", widthOut, heightOut, pixelSize); widthOut = 0u; heightOut = 0u; @@ -2685,6 +2691,7 @@ void HorizontalShear(const uint8_t* const pixelsIn, if(nullptr == pixelsOut) { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u x %u x %u\n", widthOut, heightOut, pixelSize); widthOut = 0u; heightOut = 0u; diff --git a/dali/internal/imaging/common/loader-jpeg-turbo.cpp b/dali/internal/imaging/common/loader-jpeg-turbo.cpp index 7a7f42b..5bf488d 100644 --- a/dali/internal/imaging/common/loader-jpeg-turbo.cpp +++ b/dali/internal/imaging/common/loader-jpeg-turbo.cpp @@ -894,7 +894,7 @@ bool DecodeJpeg(const Dali::ImageLoader::Input& input, std::vector(malloc(planeSize)); - if(!buffer) + if(DALI_UNLIKELY(!buffer)) { DALI_LOG_ERROR("Buffer allocation is failed [%d]\n", planeSize); pixelBuffers.clear(); @@ -982,6 +982,12 @@ bool DecodeJpeg(const Dali::ImageLoader::Input& input, std::vector(malloc(sizeof(uint8_t) * scaledPostXformWidth * scaledPostXformHeight * cmykBytesPerPixel)); + if(DALI_UNLIKELY(!cmykBuffer)) + { + DALI_LOG_ERROR("cmykBuffer allocation is failed [%zu]\n", sizeof(uint8_t) * scaledPostXformWidth * scaledPostXformHeight * cmykBytesPerPixel); + return false; + } + decodeResult = tjDecompress2(jpeg.get(), jpegBufferPtr, jpegBufferSize, reinterpret_cast(cmykBuffer), scaledPreXformWidth, 0, scaledPreXformHeight, pixelLibJpegType, flags); if(DALI_UNLIKELY(decodeResult == -1 && IsJpegDecodingFailed())) { diff --git a/dali/internal/imaging/common/loader-png.cpp b/dali/internal/imaging/common/loader-png.cpp index 8351aa7..fa855db 100644 --- a/dali/internal/imaging/common/loader-png.cpp +++ b/dali/internal/imaging/common/loader-png.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -315,7 +315,7 @@ bool LoadBitmapFromPng(const Dali::ImageLoader::Input& input, Dali::Devel::Pixel rows = reinterpret_cast(malloc(sizeof(png_bytep) * height)); if(DALI_UNLIKELY(!rows)) { - DALI_LOG_ERROR("malloc is failed\n"); + DALI_LOG_ERROR("malloc is failed. request malloc size : %zu\n", sizeof(png_bytep) * height); return false; } diff --git a/dali/internal/imaging/common/pixel-buffer-impl.cpp b/dali/internal/imaging/common/pixel-buffer-impl.cpp index 3afdce5..0ed142e 100644 --- a/dali/internal/imaging/common/pixel-buffer-impl.cpp +++ b/dali/internal/imaging/common/pixel-buffer-impl.cpp @@ -84,6 +84,10 @@ PixelBufferPtr PixelBuffer::New(uint32_t width, if(bufferSize > 0) { buffer = static_cast(malloc(bufferSize)); + if(DALI_UNLIKELY(!buffer)) + { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u\n", bufferSize); + } #if defined(DEBUG_ENABLED) gPixelBufferAllocationTotal += bufferSize; #endif @@ -180,6 +184,11 @@ Dali::PixelData PixelBuffer::CreatePixelData() const if(mBufferSize > 0) { destBuffer = static_cast(malloc(mBufferSize)); + if(DALI_UNLIKELY(!destBuffer)) + { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u\n", mBufferSize); + return Dali::PixelData(); + } memcpy(destBuffer, mBuffer, mBufferSize); } @@ -264,6 +273,10 @@ void PixelBuffer::AllocateFixedSize(uint32_t size) ReleaseBuffer(); mBuffer = reinterpret_cast(malloc(size)); mBufferSize = size; + if(DALI_UNLIKELY(!mBuffer)) + { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u\n", mBufferSize); + } #if defined(DEBUG_ENABLED) gPixelBufferAllocationTotal += size; #endif diff --git a/dali/internal/imaging/common/webp-loading.cpp b/dali/internal/imaging/common/webp-loading.cpp index 0dd3c85..24f1506 100644 --- a/dali/internal/imaging/common/webp-loading.cpp +++ b/dali/internal/imaging/common/webp-loading.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -206,7 +206,12 @@ public: if(DALI_LIKELY(!fseek(fp, 0, SEEK_SET))) { - mBuffer = reinterpret_cast(malloc(sizeof(WebPByteType) * mBufferSize)); + mBuffer = reinterpret_cast(malloc(sizeof(WebPByteType) * mBufferSize)); + if(DALI_UNLIKELY(!mBuffer)) + { + DALI_LOG_ERROR("malloc is failed. request malloc size : %zu\n", sizeof(WebPByteType) * mBufferSize); + return false; + } mBufferSize = fread(mBuffer, sizeof(WebPByteType), mBufferSize, fp); return true; } @@ -337,7 +342,7 @@ Dali::Devel::PixelBuffer WebPLoading::LoadFrame(uint32_t frameIndex, ImageDimens if(desiredSize.GetWidth() > 0 && desiredSize.GetHeight() > 0) { - const int desiredWidth = desiredSize.GetWidth(); + const int desiredWidth = desiredSize.GetWidth(); const int desiredHeight = desiredSize.GetHeight(); WebPDecoderConfig config; @@ -348,8 +353,8 @@ Dali::Devel::PixelBuffer WebPLoading::LoadFrame(uint32_t frameIndex, ImageDimens } // Apply config for scaling - config.options.use_scaling = 1; - config.options.scaled_width = desiredWidth; + config.options.use_scaling = 1; + config.options.scaled_width = desiredWidth; config.options.scaled_height = desiredHeight; if(channelNumber == 4) @@ -372,9 +377,9 @@ Dali::Devel::PixelBuffer WebPLoading::LoadFrame(uint32_t frameIndex, ImageDimens if(frameBuffer != nullptr) { - Pixel::Format pixelFormat = (channelNumber == 4) ? Pixel::RGBA8888 : Pixel::RGB888; - int32_t bufferSize = desiredWidth * desiredHeight * Dali::Pixel::GetBytesPerPixel(pixelFormat); - pixelBuffer = Dali::Devel::PixelBuffer::New(desiredWidth, desiredHeight, pixelFormat); + Pixel::Format pixelFormat = (channelNumber == 4) ? Pixel::RGBA8888 : Pixel::RGB888; + int32_t bufferSize = desiredWidth * desiredHeight * Dali::Pixel::GetBytesPerPixel(pixelFormat); + pixelBuffer = Dali::Devel::PixelBuffer::New(desiredWidth, desiredHeight, pixelFormat); memcpy(pixelBuffer.GetBuffer(), frameBuffer, bufferSize); } @@ -395,9 +400,8 @@ Dali::Devel::PixelBuffer WebPLoading::LoadFrame(uint32_t frameIndex, ImageDimens { Pixel::Format pixelFormat = (channelNumber == 4) ? Pixel::RGBA8888 : Pixel::RGB888; int32_t bufferSize = width * height * Dali::Pixel::GetBytesPerPixel(pixelFormat); - Internal::Adaptor::PixelBufferPtr internal = - Internal::Adaptor::PixelBuffer::New(frameBuffer, bufferSize, width, height, width, pixelFormat); - pixelBuffer = Devel::PixelBuffer(internal.Get()); + Internal::Adaptor::PixelBufferPtr internal = Internal::Adaptor::PixelBuffer::New(frameBuffer, bufferSize, width, height, width, pixelFormat); + pixelBuffer = Devel::PixelBuffer(internal.Get()); } } } diff --git a/dali/internal/text/text-abstraction/bidirectional-support-impl.cpp b/dali/internal/text/text-abstraction/bidirectional-support-impl.cpp index 726ac92..7439466 100644 --- a/dali/internal/text/text-abstraction/bidirectional-support-impl.cpp +++ b/dali/internal/text/text-abstraction/bidirectional-support-impl.cpp @@ -110,15 +110,17 @@ struct BidirectionalSupport::Plugin BidirectionalInfo* bidirectionalInfo = new BidirectionalInfo(); bidirectionalInfo->characterTypes = reinterpret_cast(malloc(numberOfCharacters * sizeof(FriBidiCharType))); - if(!bidirectionalInfo->characterTypes) + if(DALI_UNLIKELY(!bidirectionalInfo->characterTypes)) { + DALI_LOG_ERROR("malloc is failed. request malloc size : %zu\n", numberOfCharacters * sizeof(FriBidiCharType)); delete bidirectionalInfo; return 0; } bidirectionalInfo->embeddedLevels = reinterpret_cast(malloc(numberOfCharacters * sizeof(FriBidiLevel))); - if(!bidirectionalInfo->embeddedLevels) + if(DALI_UNLIKELY(!bidirectionalInfo->embeddedLevels)) { + DALI_LOG_ERROR("malloc is failed. request malloc size : %zu\n", numberOfCharacters * sizeof(FriBidiLevel)); free(bidirectionalInfo->characterTypes); delete bidirectionalInfo; return 0; @@ -133,7 +135,9 @@ struct BidirectionalSupport::Plugin bidirectionalInfo->bracketTypes = reinterpret_cast(malloc(numberOfCharacters * sizeof(FriBidiBracketType))); if(!bidirectionalInfo->bracketTypes) { - free(bidirectionalInfo->bracketTypes); + DALI_LOG_ERROR("malloc is failed. request malloc size : %zu\n", numberOfCharacters * sizeof(FriBidiBracketType)); + free(bidirectionalInfo->embeddedLevels); + free(bidirectionalInfo->characterTypes); delete bidirectionalInfo; return 0; } @@ -143,8 +147,9 @@ struct BidirectionalSupport::Plugin // Retrieve the embedding levels. if(fribidi_get_par_embedding_levels_ex(bidirectionalInfo->characterTypes, bidirectionalInfo->bracketTypes, numberOfCharacters, &bidirectionalInfo->paragraphDirection, bidirectionalInfo->embeddedLevels) == 0) { - free(bidirectionalInfo->characterTypes); free(bidirectionalInfo->bracketTypes); + free(bidirectionalInfo->embeddedLevels); + free(bidirectionalInfo->characterTypes); delete bidirectionalInfo; return 0; } @@ -216,7 +221,7 @@ struct BidirectionalSupport::Plugin // Copy embedded levels as fribidi_reorder_line() may change them. const size_t embeddedLevelsSize = static_cast(numberOfCharacters) * sizeof(FriBidiLevel); FriBidiLevel* embeddedLevels = reinterpret_cast(malloc(embeddedLevelsSize)); - if(embeddedLevels) + if(DALI_LIKELY(embeddedLevels)) { memcpy(embeddedLevels, bidirectionalInfo->embeddedLevels + firstCharacterIndex, embeddedLevelsSize); @@ -236,6 +241,10 @@ struct BidirectionalSupport::Plugin // Free resources. free(embeddedLevels); } + else + { + DALI_LOG_ERROR("malloc is failed. request malloc size : %zu\n", embeddedLevelsSize); + } } bool GetMirroredText(Character* text, diff --git a/dali/internal/text/text-abstraction/cairo-renderer.cpp b/dali/internal/text/text-abstraction/cairo-renderer.cpp index 03ef5dd..ed70ccb 100644 --- a/dali/internal/text/text-abstraction/cairo-renderer.cpp +++ b/dali/internal/text/text-abstraction/cairo-renderer.cpp @@ -908,6 +908,10 @@ Devel::PixelBuffer RenderTextCairo(const TextAbstraction::TextRenderer::Paramete data.buffer = newBuffer; data.compressionType = TextAbstraction::GlyphBufferData::CompressionType::NO_COMPRESSION; } + else + { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u x %u x %u\n", widthOut, heightOut, pixelSize); + } } Dali::Internal::Platform::RotateByShear(data.buffer, diff --git a/dali/internal/text/text-abstraction/hyphenation-impl.cpp b/dali/internal/text/text-abstraction/hyphenation-impl.cpp index bc460ee..972b88e 100644 --- a/dali/internal/text/text-abstraction/hyphenation-impl.cpp +++ b/dali/internal/text/text-abstraction/hyphenation-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -165,7 +165,7 @@ struct Hyphenation::Plugin } hyphens = (char*)malloc(wordLength + 5); - if(hyphens) + if(DALI_LIKELY(hyphens)) { hnj_hyphen_hyphenate2(dict, (char*)(word), wordLength, hyphens, NULL, &rep, &pos, &cut); @@ -178,6 +178,10 @@ struct Hyphenation::Plugin free(hyphens); } + else + { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u\n", wordLength + 5); + } #endif return hyphensList; diff --git a/dali/internal/text/text-abstraction/plugin/embedded-item.cpp b/dali/internal/text/text-abstraction/plugin/embedded-item.cpp index a0c8335..fc1e529 100644 --- a/dali/internal/text/text-abstraction/plugin/embedded-item.cpp +++ b/dali/internal/text/text-abstraction/plugin/embedded-item.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,8 @@ #include +#include + namespace Dali::TextAbstraction::Internal { void EmbeddedItem::GetGlyphMetrics(GlyphInfo& glyph) @@ -51,8 +53,14 @@ void EmbeddedItem::CreateBitmap(const std::vector& pixelBu // Creates the output buffer const uint32_t bufferSize = data.width * data.height * 4u; data.buffer = (uint8_t*)malloc(bufferSize); // @note The caller is responsible for deallocating the bitmap data using free. - - memset(data.buffer, 0u, bufferSize); + if(DALI_UNLIKELY(!data.buffer)) + { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u\n", bufferSize); + } + else + { + memset(data.buffer, 0u, bufferSize); + } // Just creates a void buffer. Doesn't matter what pixel format is set as is the application code the responsible of filling it. } diff --git a/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.cpp b/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.cpp index e7b8ec3..2c962a6 100644 --- a/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.cpp +++ b/dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.cpp @@ -953,6 +953,12 @@ PixelData FontClient::Plugin::CreateBitmap(FontId fontId, GlyphIndex glyphIndex, if(!data.isBufferOwned || data.compressionType != TextAbstraction::GlyphBufferData::CompressionType::NO_COMPRESSION) { uint8_t* newBuffer = (uint8_t*)malloc(data.width * data.height * Pixel::GetBytesPerPixel(data.format)); + if(DALI_UNLIKELY(!newBuffer)) + { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u x %u x %u\n", data.width, data.height, Pixel::GetBytesPerPixel(data.format)); + return Dali::PixelData(); + } + TextAbstraction::GlyphBufferData::Decompress(data, newBuffer); if(data.isBufferOwned) { diff --git a/dali/internal/text/text-abstraction/plugin/font-client-utils.cpp b/dali/internal/text/text-abstraction/plugin/font-client-utils.cpp index 5bfedb1..a6d56fa 100644 --- a/dali/internal/text/text-abstraction/plugin/font-client-utils.cpp +++ b/dali/internal/text/text-abstraction/plugin/font-client-utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -193,6 +193,12 @@ void ConvertBitmap(TextAbstraction::GlyphBufferData& data, unsigned int srcWidth { data.isBufferOwned = true; data.buffer = (uint8_t*)malloc(bufferSize); // @note The caller is responsible for deallocating the bitmap data using free. + + if(DALI_UNLIKELY(!data.buffer)) + { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u\n", bufferSize); + return; + } Dali::Internal::Platform::LanczosSample(srcBuffer, inputDimensions, srcWidth, diff --git a/dali/internal/text/text-abstraction/plugin/font-face-glyph-cache-manager.cpp b/dali/internal/text/text-abstraction/plugin/font-face-glyph-cache-manager.cpp index 96817db..0bed3f2 100644 --- a/dali/internal/text/text-abstraction/plugin/font-face-glyph-cache-manager.cpp +++ b/dali/internal/text/text-abstraction/plugin/font-face-glyph-cache-manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -168,7 +168,18 @@ bool GlyphCacheManager::LoadGlyphDataFromIndex( { glyphData.mIsBitmap = true; glyphData.mBitmap->buffer = (uint8_t*)malloc(bufferSize * sizeof(uint8_t)); // @note The caller is responsible for deallocating the bitmap data using free. - memcpy(glyphData.mBitmap->buffer, freeTypeFace->glyph->bitmap.buffer, bufferSize); + if(DALI_UNLIKELY(!glyphData.mBitmap->buffer)) + { + DALI_LOG_ERROR("malloc is failed. request malloc size : %zu\n", bufferSize * sizeof(uint8_t)); + delete glyphData.mBitmap; + glyphData.mIsBitmap = false; + glyphData.mBitmap = nullptr; + error = static_cast(-1); + } + else + { + memcpy(glyphData.mBitmap->buffer, freeTypeFace->glyph->bitmap.buffer, bufferSize); + } } else { @@ -225,12 +236,20 @@ void GlyphCacheManager::ResizeBitmapGlyph( if(glyphData.mBitmap->pitch == static_cast(glyphData.mBitmap->width)) { desiredBuffer = (uint8_t*)malloc(desiredWidth * desiredHeight * sizeof(uint8_t)); // @note The caller is responsible for deallocating the bitmap data using free. - // Resize bitmap here. - Dali::Internal::Platform::LanczosSample1BPP(glyphData.mBitmap->buffer, - inputDimensions, - glyphData.mBitmap->width, - desiredBuffer, - desiredDimensions); + + if(DALI_UNLIKELY(!desiredBuffer)) + { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u x %u x 1\n", desiredWidth, desiredHeight); + } + else + { + // Resize bitmap here. + Dali::Internal::Platform::LanczosSample1BPP(glyphData.mBitmap->buffer, + inputDimensions, + glyphData.mBitmap->width, + desiredBuffer, + desiredDimensions); + } } break; } @@ -240,12 +259,20 @@ void GlyphCacheManager::ResizeBitmapGlyph( if(glyphData.mBitmap->pitch == static_cast(glyphData.mBitmap->width << 2u)) { desiredBuffer = (uint8_t*)malloc((desiredWidth * desiredHeight * sizeof(uint8_t)) << 2u); // @note The caller is responsible for deallocating the bitmap data using free. - // Resize bitmap here. - Dali::Internal::Platform::LanczosSample4BPP(glyphData.mBitmap->buffer, - inputDimensions, - glyphData.mBitmap->width, - desiredBuffer, - desiredDimensions); + + if(DALI_UNLIKELY(!desiredBuffer)) + { + DALI_LOG_ERROR("malloc is failed. request malloc size : %u x %u x 4\n", desiredWidth, desiredHeight); + } + else + { + // Resize bitmap here. + Dali::Internal::Platform::LanczosSample4BPP(glyphData.mBitmap->buffer, + inputDimensions, + glyphData.mBitmap->width, + desiredBuffer, + desiredDimensions); + } } break; } -- 2.7.4