From 11080b25d00bdf1489f4fba2b2613022181308de Mon Sep 17 00:00:00 2001 From: caochuan Date: Mon, 11 Oct 2021 10:55:14 +0800 Subject: [PATCH 1/8] Add big image parcel func Signed-off-by: caochuan --- .../innerkitsimpl/common/src/pixel_map.cpp | 246 +++++++++++++----- .../test/unittest/image_pixel_map_test.cpp | 65 ++++- interfaces/innerkits/include/pixel_map.h | 12 +- 3 files changed, 256 insertions(+), 67 deletions(-) diff --git a/frameworks/innerkitsimpl/common/src/pixel_map.cpp b/frameworks/innerkitsimpl/common/src/pixel_map.cpp index a537f99f8..a28a57b2a 100644 --- a/frameworks/innerkitsimpl/common/src/pixel_map.cpp +++ b/frameworks/innerkitsimpl/common/src/pixel_map.cpp @@ -25,9 +25,10 @@ #include "pixel_map_parcel.h" #include "post_proc.h" #include "parcel.h" -#include "ipc_file_descriptor.h" #ifndef _WIN32 #include "securec.h" +#include "sys_binder.h" +#include "ipc_file_descriptor.h" #else #include "memory.h" #endif @@ -111,12 +112,14 @@ void PixelMap::SetPixelsAddr(void *addr, void *context, uint32_t size, Allocator unique_ptr PixelMap::Create(const uint32_t *colors, uint32_t colorLength, const InitializationOptions &opts) { + HiLog::Info(LABEL, "PixelMap::Create1 enter"); return Create(colors, colorLength, 0, opts.size.width, opts); } unique_ptr PixelMap::Create(const uint32_t *colors, uint32_t colorLength, int32_t offset, int32_t stride, const InitializationOptions &opts) { + HiLog::Info(LABEL, "PixelMap::Create2 enter"); if (!CheckParams(colors, colorLength, offset, stride, opts)) { return nullptr; } @@ -194,6 +197,7 @@ bool PixelMap::CheckParams(const uint32_t *colors, uint32_t colorLength, int32_t unique_ptr PixelMap::Create(const InitializationOptions &opts) { + HiLog::Info(LABEL, "PixelMap::Create3 enter"); unique_ptr dstPixelMap = make_unique(); if (dstPixelMap == nullptr) { HiLog::Error(LABEL, "create pixelMap pointer fail"); @@ -245,12 +249,14 @@ void PixelMap::UpdatePixelsAlpha(const AlphaType &alphaType, const PixelFormat & unique_ptr PixelMap::Create(PixelMap &source, const InitializationOptions &opts) { + HiLog::Info(LABEL, "PixelMap::Create4 enter"); Rect rect; return Create(source, rect, opts); } unique_ptr PixelMap::Create(PixelMap &source, const Rect &srcRect, const InitializationOptions &opts) { + HiLog::Info(LABEL, "PixelMap::Create5 enter"); ImageInfo srcImageInfo; source.GetImageInfo(srcImageInfo); PostProc postProc; @@ -639,6 +645,7 @@ int32_t PixelMap::GetRowBytes() int32_t PixelMap::GetByteCount() { + HiLog::Debug(LABEL, "GetByteCount"); return rowDataSize_ * imageInfo_.size.height; } @@ -705,15 +712,18 @@ uint8_t PixelMap::GetARGB32ColorB(uint32_t color) bool PixelMap::IsSameImage(const PixelMap &other) { if (data_ == nullptr || other.data_ == nullptr) { + HiLog::Error(LABEL, "IsSameImage data_ is nullptr."); return false; } if (imageInfo_.size.width != other.imageInfo_.size.width || imageInfo_.size.height != other.imageInfo_.size.height || imageInfo_.pixelFormat != other.imageInfo_.pixelFormat || imageInfo_.alphaType != other.imageInfo_.alphaType) { + HiLog::Error(LABEL, "IsSameImage imageInfo check not OK."); return false; } uint64_t size = static_cast(rowDataSize_) * imageInfo_.size.height; if (memcmp(data_, other.data_, size) != 0) { + HiLog::Error(LABEL, "IsSameImage mmemcmp check not OK."); return false; } return true; @@ -1011,7 +1021,144 @@ void *PixelMap::GetFd() const return context_; } -bool PixelMap::WriteFileDescriptor(Parcel &data, int fd) const +void PixelMap::ReleaseMemory(AllocatorType allocType, void *addr, void *context, uint32_t size) +{ + if (allocType == AllocatorType::SHARE_MEM_ALLOC) { +#if !defined(_WIN32) && !defined(_APPLE) + int *fd = static_cast(context); + if (addr != nullptr) { + ::munmap(addr, size); + } + if (fd != nullptr) { + ::close(*fd); + delete fd; + } +#endif + } else if (allocType == AllocatorType::HEAP_ALLOC) { + if (addr != nullptr) { + free(addr); + addr = nullptr; + } + } +} + +bool PixelMap::WriteImageData(Parcel &parcel, const void *data, size_t size) +{ + if (data == nullptr || size > MAX_IMAGEDATA_SIZE) { + return false; + } + + if (!parcel.WriteInt32(size)) { + return false; + } + if (size <= MIN_IMAGEDATA_SIZE) { + return parcel.WriteUnpadBuffer(data, size); + } +#if !defined(_WIN32) && !defined(_APPLE) + int fd = AshmemCreate("Parcel ImageData", size); + HiLog::Info(LABEL, "AshmemCreate:[%{public}d].", fd); + if (fd < 0) { + return false; + } + + int result = AshmemSetProt(fd, PROT_READ | PROT_WRITE); + HiLog::Info(LABEL, "AshmemSetProt:[%{public}d].", result); + if (result < 0) { + return false; + } + void *ptr = ::mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + + if (ptr == MAP_FAILED) { + return false; + } + HiLog::Info(LABEL, "mmap success"); + + if (memcpy_s(ptr, size, data, size) != EOK) { + ::munmap(ptr, size); + HiLog::Error(LABEL, "WriteImageData memcpy_s error"); + return false; + } + + // int dupFd = dup(fd); + // HiLog::Info(LABEL, "AshmemCreate dupFd:[%{public}d].", dupFd); + + // if (dupFd < 0) { + // return false; + // } + // HiLog::Info(LABEL, "AshmemCreate dupFd2:[%{public}d].", dupFd); + if (!WriteFileDescriptor(parcel, fd)) { + ::munmap(ptr, size); + HiLog::Error(LABEL, "WriteImageData WriteFileDescriptor error"); + return false; + } + HiLog::Debug(LABEL, "WriteImageData WriteFileDescriptor success"); + HiLog::Debug(LABEL, "WriteImageData End"); +#endif + return true; +} + +uint8_t *PixelMap::ReadImageData(Parcel &parcel, size_t bufferSize) +{ + uint8_t *base = nullptr; + int fd = -1; + AllocatorType allocType = AllocatorType::HEAP_ALLOC; + HiLog::Info(LABEL, "ReadImageData bufferSize :[%{public}d]", bufferSize); + + if (static_cast(bufferSize) <= MIN_IMAGEDATA_SIZE) { + const uint8_t *ptr = parcel.ReadUnpadBuffer(bufferSize); + base = static_cast(malloc(bufferSize)); + if (base == nullptr) { + HiLog::Error(LABEL, "alloc output pixel memory size:[%{public}d] error.", bufferSize); + return nullptr; + } + if (memcpy_s(base, bufferSize, ptr, bufferSize) != 0) { + free(base); + base = nullptr; + HiLog::Error(LABEL, "memcpy pixel data size:[%{public}d] error.", bufferSize); + return nullptr; + } + } else { +#if !defined(_WIN32) && !defined(_APPLE) + allocType = AllocatorType::SHARE_MEM_ALLOC; + fd = ReadFileDescriptor(parcel); + HiLog::Info(LABEL, "ReadImageData fd32 :[%{public}d]", fd); + if (fd < 0) { + HiLog::Error(LABEL, "read fd :[%{public}d] error", fd); + return nullptr; + } + + // int ashmemSize = AshmemGetSize(fd); + // if (ashmemSize < 0 || size_t(ashmemSize) < bufferSize) { + // // do not close fd here. fd will be closed in FileDescriptor, ::close(fd) + // HiLog::Error(LABEL, "read ashmemSize :[%{public}d] error", ashmemSize); + // return nullptr; + // } + void *ptr = ::mmap(nullptr, bufferSize, PROT_READ, MAP_SHARED, fd, 0); + if (ptr == MAP_FAILED) { + // do not close fd here. fd will be closed in FileDescriptor, ::close(fd) + HiLog::Error(LABEL, "mmap error"); + return nullptr; + } + base = static_cast(malloc(bufferSize)); + if (base == nullptr) { + HiLog::Error(LABEL, "alloc output pixel memory size:[%{public}d] error.", bufferSize); + return nullptr; + } + if (memcpy_s(base, bufferSize, ptr, bufferSize) != 0) { + free(base); + base = nullptr; + HiLog::Error(LABEL, "memcpy pixel data size:[%{public}d] error.", bufferSize); + return nullptr; + } + + ReleaseMemory(allocType, ptr, &fd, bufferSize); +#endif + } + + return base; +} + +bool PixelMap::WriteFileDescriptor(Parcel &parcel, int fd) { if (fd < 0) { return false; @@ -1021,12 +1168,12 @@ bool PixelMap::WriteFileDescriptor(Parcel &data, int fd) const return false; } sptr descriptor = new IPCFileDescriptor(dupFd); - return data.WriteObject(descriptor); + return parcel.WriteObject(descriptor); } -int PixelMap::ReadFileDescriptor(Parcel &data) +int PixelMap::ReadFileDescriptor(Parcel &parcel) { - sptr descriptor = data.ReadObject(); + sptr descriptor = parcel.ReadObject(); if (descriptor == nullptr) { return -1; } @@ -1037,66 +1184,65 @@ int PixelMap::ReadFileDescriptor(Parcel &data) return dup(fd); } -bool PixelMap::Marshalling(Parcel &data) const +bool PixelMap::Marshalling(Parcel &parcel) const { int32_t PIXEL_MAP_INFO_MAX_LENGTH = 128; int32_t bufferSize = rowDataSize_ * imageInfo_.size.height; - if (static_cast(bufferSize + PIXEL_MAP_INFO_MAX_LENGTH) > data.GetDataCapacity() && - !data.SetDataCapacity(bufferSize + PIXEL_MAP_INFO_MAX_LENGTH)) { + if (static_cast(bufferSize + PIXEL_MAP_INFO_MAX_LENGTH) > parcel.GetDataCapacity() && + !parcel.SetDataCapacity(bufferSize + PIXEL_MAP_INFO_MAX_LENGTH)) { HiLog::Error(LABEL, "set parcel max capacity:[%{public}d] failed.", bufferSize + PIXEL_MAP_INFO_MAX_LENGTH); return false; } - if (!data.WriteInt32(imageInfo_.size.width)) { + if (!parcel.WriteInt32(imageInfo_.size.width)) { HiLog::Error(LABEL, "write pixel map width:[%{public}d] to parcel failed.", imageInfo_.size.width); return false; } - if (!data.WriteInt32(imageInfo_.size.height)) { + if (!parcel.WriteInt32(imageInfo_.size.height)) { HiLog::Error(LABEL, "write pixel map height:[%{public}d] to parcel failed.", imageInfo_.size.height); return false; } - if (!data.WriteInt32(static_cast(imageInfo_.pixelFormat))) { + if (!parcel.WriteInt32(static_cast(imageInfo_.pixelFormat))) { HiLog::Error(LABEL, "write pixel map pixel format:[%{public}d] to parcel failed.", imageInfo_.pixelFormat); return false; } - if (!data.WriteInt32(static_cast(imageInfo_.colorSpace))) { + if (!parcel.WriteInt32(static_cast(imageInfo_.colorSpace))) { HiLog::Error(LABEL, "write pixel map color space:[%{public}d] to parcel failed.", imageInfo_.colorSpace); return false; } - if (!data.WriteInt32(static_cast(imageInfo_.alphaType))) { + if (!parcel.WriteInt32(static_cast(imageInfo_.alphaType))) { HiLog::Error(LABEL, "write pixel map alpha type:[%{public}d] to parcel failed.", imageInfo_.alphaType); return false; } - if (!data.WriteInt32(imageInfo_.baseDensity)) { + if (!parcel.WriteInt32(imageInfo_.baseDensity)) { HiLog::Error(LABEL, "write pixel map base density:[%{public}d] to parcel failed.", imageInfo_.baseDensity); return false; } - if (!data.WriteInt32(bufferSize)) { - HiLog::Error(LABEL, "write pixel map buffer size:[%{public}d] to parcel failed.", bufferSize); - return false; - } - if (!data.WriteInt32(static_cast(allocatorType_))) { + if (!parcel.WriteInt32(static_cast(allocatorType_))) { HiLog::Error(LABEL, "write pixel map allocator type:[%{public}d] to parcel failed.", allocatorType_); return false; } if (allocatorType_ == AllocatorType::SHARE_MEM_ALLOC) { +#if !defined(_WIN32) && !defined(_APPLE) int *fd = static_cast(context_); if (*fd < 0) { HiLog::Error(LABEL, "write pixel map failed, fd < 0."); return false; } - if (!WriteFileDescriptor(data, *fd)) { + + if (!WriteFileDescriptor(parcel, *fd)) { HiLog::Error(LABEL, "write pixel map fd:[%{public}d] to parcel failed.", *fd); return false; } +#endif } else { const uint8_t *addr = data_; if (addr == nullptr) { HiLog::Error(LABEL, "write to parcel failed, pixel memory is null."); return false; } - if (!data.WriteBuffer(addr, bufferSize)) { + if (!WriteImageData(parcel, addr, bufferSize)) { HiLog::Error(LABEL, "write pixel map buffer to parcel failed."); return false; } @@ -1104,7 +1250,7 @@ bool PixelMap::Marshalling(Parcel &data) const return true; } -PixelMap *PixelMap::Unmarshalling(Parcel &data) +PixelMap *PixelMap::Unmarshalling(Parcel &parcel) { PixelMap *pixelMap = new PixelMap(); if (pixelMap == nullptr) { @@ -1113,18 +1259,24 @@ PixelMap *PixelMap::Unmarshalling(Parcel &data) } ImageInfo imgInfo; - imgInfo.size.width = data.ReadInt32(); - imgInfo.size.height = data.ReadInt32(); - imgInfo.pixelFormat = static_cast(data.ReadInt32()); - imgInfo.colorSpace = static_cast(data.ReadInt32()); - imgInfo.alphaType = static_cast(data.ReadInt32()); - imgInfo.baseDensity = data.ReadInt32(); - int32_t bufferSize = data.ReadInt32(); - AllocatorType allocType = static_cast(data.ReadInt32()); + imgInfo.size.width = parcel.ReadInt32(); + HiLog::Debug(LABEL, "read pixel map width:[%{public}d] to parcel.", imgInfo.size.width); + imgInfo.size.height = parcel.ReadInt32(); + HiLog::Debug(LABEL, "read pixel map height:[%{public}d] to parcel.", imgInfo.size.height); + imgInfo.pixelFormat = static_cast(parcel.ReadInt32()); + HiLog::Debug(LABEL, "read pixel map pixelFormat:[%{public}d] to parcel.", imgInfo.pixelFormat); + imgInfo.colorSpace = static_cast(parcel.ReadInt32()); + HiLog::Debug(LABEL, "read pixel map colorSpace:[%{public}d] to parcel.", imgInfo.colorSpace); + imgInfo.alphaType = static_cast(parcel.ReadInt32()); + HiLog::Debug(LABEL, "read pixel map alphaType:[%{public}d] to parcel.", imgInfo.alphaType); + imgInfo.baseDensity = parcel.ReadInt32(); + AllocatorType allocType = static_cast(parcel.ReadInt32()); + int32_t bufferSize = parcel.ReadInt32(); uint8_t *base = nullptr; void *context = nullptr; if (allocType == AllocatorType::SHARE_MEM_ALLOC) { - int fd = ReadFileDescriptor(data); +#if !defined(_WIN32) && !defined(_APPLE) + int fd = ReadFileDescriptor(parcel); if (fd < 0) { HiLog::Error(LABEL, "fd < 0"); return nullptr; @@ -1145,42 +1297,18 @@ PixelMap *PixelMap::Unmarshalling(Parcel &data) } *static_cast(context) = fd; base = static_cast(ptr); +#endif } else { - const uint8_t *addr = data.ReadBuffer(bufferSize); - if (addr == nullptr) { - HiLog::Error(LABEL, "read buffer from parcel failed, read buffer addr is null"); - return nullptr; - } - base = static_cast(malloc(bufferSize)); + base = ReadImageData(parcel, bufferSize); if (base == nullptr) { - HiLog::Error(LABEL, "alloc output pixel memory size:[%{public}d] error.", bufferSize); - return nullptr; - } - if (memcpy_s(base, bufferSize, addr, bufferSize) != 0) { - free(base); - base = nullptr; - HiLog::Error(LABEL, "memcpy pixel data size:[%{public}d] error.", bufferSize); + HiLog::Error(LABEL, "get pixel memory size:[%{public}d] error.", bufferSize); return nullptr; } } uint32_t ret = pixelMap->SetImageInfo(imgInfo); if (ret != SUCCESS) { - if (allocType == AllocatorType::SHARE_MEM_ALLOC) { - int *fd = static_cast(context); - if (base != nullptr) { - ::munmap(base, bufferSize); - } - if (fd != nullptr) { - ::close(*fd); - delete fd; - } - } else if (allocType == AllocatorType::HEAP_ALLOC) { - if (base != nullptr) { - free(base); - base = nullptr; - } - } + ReleaseMemory(allocType, base, context, bufferSize); HiLog::Error(LABEL, "create pixel map from parcel failed, set image info error."); return nullptr; } diff --git a/frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp b/frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp index c99068414..a0c5d110c 100644 --- a/frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp @@ -58,6 +58,30 @@ public: return pixelMap; } + + std::unique_ptr ConstructBigPixmap() + { + int32_t pixelMapWidth = 4 * 1024; + int32_t pixelMapHeight = 3 * 100; + std::unique_ptr pixelMap = std::make_unique(); + ImageInfo info; + info.size.width = pixelMapWidth; + info.size.height = pixelMapHeight; + info.pixelFormat = PixelFormat::RGB_888; + info.colorSpace = ColorSpace::SRGB; + pixelMap->SetImageInfo(info); + + int32_t bufferSize = pixelMap->GetByteCount(); + void *buffer = malloc(bufferSize); + char *ch = (char *)buffer; + for (int32_t i = 0; i < bufferSize; i++) { + *(ch++) = 'a'; + } + + pixelMap->SetPixelsAddr(buffer, nullptr, bufferSize, AllocatorType::HEAP_ALLOC, nullptr); + + return pixelMap; + } /** * @tc.name: ImagePixelMap001 * @tc.desc: ALPHA_8 pixel format pixel map operation @@ -469,22 +493,16 @@ HWTEST_F(ImagePixelMapTest, ImagePixelMap011, TestSize.Level3) GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap011 start"; Parcel data; - std::unique_ptr pixelmap1 = ConstructPixmap(); - bool ret = pixelmap1.get()->Marshalling(data); - EXPECT_EQ(true, ret); PixelMap *pixelmap2 = PixelMap::Unmarshalling(data); - EXPECT_EQ(pixelmap1->GetHeight(), pixelmap2->GetHeight()); EXPECT_EQ(pixelmap1->GetWidth(), pixelmap2->GetWidth()); EXPECT_EQ(pixelmap1->GetPixelFormat(), pixelmap2->GetPixelFormat()); EXPECT_EQ(pixelmap1->GetColorSpace(), pixelmap2->GetColorSpace()); - EXPECT_EQ(true, pixelmap1->IsSameImage(*pixelmap2)); - GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap011 end"; } /** @@ -513,5 +531,40 @@ HWTEST_F(ImagePixelMapTest, ImagePixelMap012, TestSize.Level3) EXPECT_EQ(newPixelMap, nullptr); GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap012 end"; } + + +/** +* @tc.name: ImagePixelMap013 +* @tc.desc: test CreateFromParcel +* @tc.type: FUNC +* @tc.require: AR000FTAMO +*/ +HWTEST_F(ImagePixelMapTest, ImagePixelMap013, TestSize.Level3) +{ + GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap013 start"; + + Parcel data; + std::unique_ptr pixelmap1 = ConstructBigPixmap(); + GTEST_LOG_(INFO) << "ImagePixelMap013 ConstructPixmap success"; + bool ret = pixelmap1.get()->Marshalling(data); + GTEST_LOG_(INFO) << "ImagePixelMap013 Marshalling success"; + EXPECT_EQ(true, ret); + + PixelMap *pixelmap2 = PixelMap::Unmarshalling(data); + GTEST_LOG_(INFO) << "ImagePixelMap013 Unmarshalling success"; + GTEST_LOG_(INFO) << "ImagePixelMap013 pixelmap1 GetHeight :" << pixelmap1->GetHeight(); + GTEST_LOG_(INFO) << "ImagePixelMap013 pixelmap2 GetHeight :" << pixelmap2->GetHeight(); + EXPECT_EQ(pixelmap1->GetHeight(), pixelmap2->GetHeight()); + GTEST_LOG_(INFO) << "ImagePixelMap013 GetHeight success"; + EXPECT_EQ(pixelmap1->GetWidth(), pixelmap2->GetWidth()); + GTEST_LOG_(INFO) << "ImagePixelMap013 GetWidth success"; + EXPECT_EQ(pixelmap1->GetPixelFormat(), pixelmap2->GetPixelFormat()); + GTEST_LOG_(INFO) << "ImagePixelMap013 GetPixelFormat success"; + EXPECT_EQ(pixelmap1->GetColorSpace(), pixelmap2->GetColorSpace()); + GTEST_LOG_(INFO) << "ImagePixelMap013 GetColorSpace success"; + EXPECT_EQ(true, pixelmap1->IsSameImage(*pixelmap2)); + GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap013 end"; +} + } // namespace Multimedia } // namespace OHOS \ No newline at end of file diff --git a/interfaces/innerkits/include/pixel_map.h b/interfaces/innerkits/include/pixel_map.h index 68a5a44b8..40b4fdf84 100644 --- a/interfaces/innerkits/include/pixel_map.h +++ b/interfaces/innerkits/include/pixel_map.h @@ -120,6 +120,8 @@ public: NATIVEEXPORT bool Marshalling(Parcel &data) const override; NATIVEEXPORT static PixelMap *Unmarshalling(Parcel &data); private: + static constexpr size_t MAX_IMAGEDATA_SIZE = 128 * 1024 * 1024; // 128M + static constexpr size_t MIN_IMAGEDATA_SIZE = 32 * 1024; // 32k friend class ImageSource; static bool ALPHA8ToARGB(const uint8_t *in, uint32_t inCount, uint32_t *out, uint32_t outCount); static bool RGB565ToARGB(const uint8_t *in, uint32_t inCount, uint32_t *out, uint32_t outCount); @@ -162,8 +164,14 @@ private: ? false : true; } - bool WriteFileDescriptor(Parcel &data, int fd) const; - static int ReadFileDescriptor(Parcel &data); + + static void ReleaseMemory(AllocatorType allocType, void *addr, void *context, uint32_t size); + static bool WriteImageData(Parcel &parcel, const void *data, size_t size); + static uint8_t *ReadImageData(Parcel &parcel, size_t size); + + static int ReadFileDescriptor(Parcel &parcel); + + static bool WriteFileDescriptor(Parcel &parcel, int fd); uint8_t *data_ = nullptr; // this info SHOULD be the final info for decoded pixelmap, not the original image info -- Gitee From 0e4b8cd0db8ba8971196c4b1a6d54460ce6d31cd Mon Sep 17 00:00:00 2001 From: caochuan Date: Mon, 11 Oct 2021 16:53:11 +0800 Subject: [PATCH 2/8] Fix CodeCheck issue Signed-off-by: caochuan --- .../innerkitsimpl/common/src/pixel_map.cpp | 114 +++++++++++------- .../test/unittest/image_pixel_map_test.cpp | 16 ++- interfaces/innerkits/include/pixel_map.h | 6 +- 3 files changed, 85 insertions(+), 51 deletions(-) diff --git a/frameworks/innerkitsimpl/common/src/pixel_map.cpp b/frameworks/innerkitsimpl/common/src/pixel_map.cpp index a28a57b2a..b1d08ffed 100644 --- a/frameworks/innerkitsimpl/common/src/pixel_map.cpp +++ b/frameworks/innerkitsimpl/common/src/pixel_map.cpp @@ -22,12 +22,10 @@ #include "media_errors.h" #include "pixel_convert_adapter.h" #include "pixel_map_utils.h" -#include "pixel_map_parcel.h" #include "post_proc.h" #include "parcel.h" #ifndef _WIN32 #include "securec.h" -#include "sys_binder.h" #include "ipc_file_descriptor.h" #else #include "memory.h" @@ -49,6 +47,9 @@ constexpr uint8_t BGRA_ALPHA_INDEX = 3; constexpr uint8_t BGRA_BYTES = 4; constexpr uint8_t PER_PIXEL_LEN = 1; +constexpr uint8_t FILL_NUMBER = 3; +constexpr uint8_t ALIGN_NUMBER = 4; + PixelMap::~PixelMap() { FreePixelMap(); @@ -213,6 +214,10 @@ unique_ptr PixelMap::Create(const InitializationOptions &opts) return nullptr; } uint32_t bufferSize = dstPixelMap->GetByteCount(); + if (bufferSize <= 0) { + HiLog::Error(LABEL, "calloc parameter bufferSize:[%{public}d] error.", bufferSize); + return nullptr; + } uint8_t *dstPixels = static_cast(calloc(bufferSize, 1)); if (dstPixels == nullptr) { HiLog::Error(LABEL, "allocate memory size %{public}u fail", bufferSize); @@ -311,6 +316,10 @@ bool PixelMap::SourceCropAndConvert(PixelMap &source, const ImageInfo &srcImageI const Rect &srcRect, PixelMap &dstPixelMap) { uint32_t bufferSize = dstPixelMap.GetByteCount(); + if (bufferSize <= 0) { + HiLog::Error(LABEL, "malloc parameter bufferSize:[%{public}d] error.", bufferSize); + return false; + } void *dstPixels = malloc(bufferSize); if (dstPixels == nullptr) { HiLog::Error(LABEL, "allocate memory size %{public}u fail", bufferSize); @@ -371,10 +380,14 @@ void PixelMap::InitDstImageInfo(const InitializationOptions &opts, const ImageIn bool PixelMap::CopyPixelMap(PixelMap &source, PixelMap &dstPixelMap) { uint32_t bufferSize = source.GetByteCount(); - if (bufferSize == 0 || source.GetPixels() == nullptr) { + if (source.GetPixels() == nullptr) { HiLog::Error(LABEL, "source pixelMap data invalid"); return false; } + if (bufferSize <= 0) { + HiLog::Error(LABEL, "malloc parameter bufferSize:[%{public}d] error.", bufferSize); + return false; + } uint8_t *dstPixels = static_cast(malloc(bufferSize)); if (dstPixels == nullptr) { HiLog::Error(LABEL, "allocate memory size %{public}u fail", bufferSize); @@ -472,7 +485,7 @@ uint32_t PixelMap::SetImageInfo(ImageInfo &info, bool isReused) return ERR_IMAGE_TOO_LARGE; } if (info.pixelFormat == PixelFormat::ALPHA_8) { - rowDataSize_ = pixelBytes_ * ((info.size.width + 3) / 4 * 4); + rowDataSize_ = pixelBytes_ * ((info.size.width + FILL_NUMBER) / ALIGN_NUMBER * ALIGN_NUMBER); HiLog::Info(LABEL, "ALPHA_8 rowDataSize_ %{public}d.", rowDataSize_); } else { rowDataSize_ = pixelBytes_ * info.size.width; @@ -1079,13 +1092,6 @@ bool PixelMap::WriteImageData(Parcel &parcel, const void *data, size_t size) return false; } - // int dupFd = dup(fd); - // HiLog::Info(LABEL, "AshmemCreate dupFd:[%{public}d].", dupFd); - - // if (dupFd < 0) { - // return false; - // } - // HiLog::Info(LABEL, "AshmemCreate dupFd2:[%{public}d].", dupFd); if (!WriteFileDescriptor(parcel, fd)) { ::munmap(ptr, size); HiLog::Error(LABEL, "WriteImageData WriteFileDescriptor error"); @@ -1097,15 +1103,18 @@ bool PixelMap::WriteImageData(Parcel &parcel, const void *data, size_t size) return true; } -uint8_t *PixelMap::ReadImageData(Parcel &parcel, size_t bufferSize) +uint8_t *PixelMap::ReadImageData(Parcel &parcel, int32_t bufferSize) { uint8_t *base = nullptr; int fd = -1; AllocatorType allocType = AllocatorType::HEAP_ALLOC; - HiLog::Info(LABEL, "ReadImageData bufferSize :[%{public}d]", bufferSize); if (static_cast(bufferSize) <= MIN_IMAGEDATA_SIZE) { const uint8_t *ptr = parcel.ReadUnpadBuffer(bufferSize); + if (bufferSize <= 0) { + HiLog::Error(LABEL, "malloc parameter bufferSize:[%{public}d] error.", bufferSize); + return nullptr; + } base = static_cast(malloc(bufferSize)); if (base == nullptr) { HiLog::Error(LABEL, "alloc output pixel memory size:[%{public}d] error.", bufferSize); @@ -1121,24 +1130,20 @@ uint8_t *PixelMap::ReadImageData(Parcel &parcel, size_t bufferSize) #if !defined(_WIN32) && !defined(_APPLE) allocType = AllocatorType::SHARE_MEM_ALLOC; fd = ReadFileDescriptor(parcel); - HiLog::Info(LABEL, "ReadImageData fd32 :[%{public}d]", fd); if (fd < 0) { HiLog::Error(LABEL, "read fd :[%{public}d] error", fd); return nullptr; } - - // int ashmemSize = AshmemGetSize(fd); - // if (ashmemSize < 0 || size_t(ashmemSize) < bufferSize) { - // // do not close fd here. fd will be closed in FileDescriptor, ::close(fd) - // HiLog::Error(LABEL, "read ashmemSize :[%{public}d] error", ashmemSize); - // return nullptr; - // } void *ptr = ::mmap(nullptr, bufferSize, PROT_READ, MAP_SHARED, fd, 0); if (ptr == MAP_FAILED) { // do not close fd here. fd will be closed in FileDescriptor, ::close(fd) HiLog::Error(LABEL, "mmap error"); return nullptr; } + if (bufferSize <= 0) { + HiLog::Error(LABEL, "malloc parameter bufferSize:[%{public}d] error.", bufferSize); + return nullptr; + } base = static_cast(malloc(bufferSize)); if (base == nullptr) { HiLog::Error(LABEL, "alloc output pixel memory size:[%{public}d] error.", bufferSize); @@ -1184,40 +1189,51 @@ int PixelMap::ReadFileDescriptor(Parcel &parcel) return dup(fd); } -bool PixelMap::Marshalling(Parcel &parcel) const +bool PixelMap::WriteImageInfo(Parcel &parcel) const { - int32_t PIXEL_MAP_INFO_MAX_LENGTH = 128; - int32_t bufferSize = rowDataSize_ * imageInfo_.size.height; - - if (static_cast(bufferSize + PIXEL_MAP_INFO_MAX_LENGTH) > parcel.GetDataCapacity() && - !parcel.SetDataCapacity(bufferSize + PIXEL_MAP_INFO_MAX_LENGTH)) { - HiLog::Error(LABEL, "set parcel max capacity:[%{public}d] failed.", bufferSize + PIXEL_MAP_INFO_MAX_LENGTH); - return false; - } if (!parcel.WriteInt32(imageInfo_.size.width)) { - HiLog::Error(LABEL, "write pixel map width:[%{public}d] to parcel failed.", imageInfo_.size.width); + HiLog::Error(LABEL, "write image info width:[%{public}d] to parcel failed.", imageInfo_.size.width); return false; } if (!parcel.WriteInt32(imageInfo_.size.height)) { - HiLog::Error(LABEL, "write pixel map height:[%{public}d] to parcel failed.", imageInfo_.size.height); + HiLog::Error(LABEL, "write image info height:[%{public}d] to parcel failed.", imageInfo_.size.height); return false; } if (!parcel.WriteInt32(static_cast(imageInfo_.pixelFormat))) { - HiLog::Error(LABEL, "write pixel map pixel format:[%{public}d] to parcel failed.", imageInfo_.pixelFormat); + HiLog::Error(LABEL, "write image info pixel format:[%{public}d] to parcel failed.", imageInfo_.pixelFormat); return false; } if (!parcel.WriteInt32(static_cast(imageInfo_.colorSpace))) { - HiLog::Error(LABEL, "write pixel map color space:[%{public}d] to parcel failed.", imageInfo_.colorSpace); + HiLog::Error(LABEL, "write image info color space:[%{public}d] to parcel failed.", imageInfo_.colorSpace); return false; } if (!parcel.WriteInt32(static_cast(imageInfo_.alphaType))) { - HiLog::Error(LABEL, "write pixel map alpha type:[%{public}d] to parcel failed.", imageInfo_.alphaType); + HiLog::Error(LABEL, "write image info alpha type:[%{public}d] to parcel failed.", imageInfo_.alphaType); return false; } if (!parcel.WriteInt32(imageInfo_.baseDensity)) { - HiLog::Error(LABEL, "write pixel map base density:[%{public}d] to parcel failed.", imageInfo_.baseDensity); + HiLog::Error(LABEL, "write image info base density:[%{public}d] to parcel failed.", imageInfo_.baseDensity); + return false; + } + return true; +} + +bool PixelMap::Marshalling(Parcel &parcel) const +{ + int32_t PIXEL_MAP_INFO_MAX_LENGTH = 128; + int32_t bufferSize = rowDataSize_ * imageInfo_.size.height; + + if (static_cast(bufferSize + PIXEL_MAP_INFO_MAX_LENGTH) > parcel.GetDataCapacity() && + !parcel.SetDataCapacity(bufferSize + PIXEL_MAP_INFO_MAX_LENGTH)) { + HiLog::Error(LABEL, "set parcel max capacity:[%{public}d] failed.", bufferSize + PIXEL_MAP_INFO_MAX_LENGTH); return false; } + + if (!WriteImageInfo(parcel)) { + HiLog::Error(LABEL, "write image info to parcel failed."); + return false; + } + if (!parcel.WriteInt32(static_cast(allocatorType_))) { HiLog::Error(LABEL, "write pixel map allocator type:[%{public}d] to parcel failed.", allocatorType_); @@ -1250,15 +1266,8 @@ bool PixelMap::Marshalling(Parcel &parcel) const return true; } -PixelMap *PixelMap::Unmarshalling(Parcel &parcel) +bool PixelMap::ReadImageInfo(Parcel &parcel, ImageInfo &imgInfo) { - PixelMap *pixelMap = new PixelMap(); - if (pixelMap == nullptr) { - HiLog::Error(LABEL, "create pixelmap pointer fail"); - return nullptr; - } - - ImageInfo imgInfo; imgInfo.size.width = parcel.ReadInt32(); HiLog::Debug(LABEL, "read pixel map width:[%{public}d] to parcel.", imgInfo.size.width); imgInfo.size.height = parcel.ReadInt32(); @@ -1270,6 +1279,23 @@ PixelMap *PixelMap::Unmarshalling(Parcel &parcel) imgInfo.alphaType = static_cast(parcel.ReadInt32()); HiLog::Debug(LABEL, "read pixel map alphaType:[%{public}d] to parcel.", imgInfo.alphaType); imgInfo.baseDensity = parcel.ReadInt32(); + return true; +} + +PixelMap *PixelMap::Unmarshalling(Parcel &parcel) +{ + PixelMap *pixelMap = new PixelMap(); + if (pixelMap == nullptr) { + HiLog::Error(LABEL, "create pixelmap pointer fail"); + return nullptr; + } + + ImageInfo imgInfo; + if (!pixelMap->ReadImageInfo(parcel,imgInfo)) { + HiLog::Error(LABEL, "read imageInfo fail"); + return nullptr; + } + AllocatorType allocType = static_cast(parcel.ReadInt32()); int32_t bufferSize = parcel.ReadInt32(); uint8_t *base = nullptr; diff --git a/frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp b/frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp index a0c5d110c..c2f56d82a 100644 --- a/frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp @@ -27,6 +27,8 @@ static constexpr int32_t PIXEL_MAP_TEST_HEIGHT = 3; static constexpr int32_t PIXEL_MAP_RGB565_BYTE = 2; static constexpr int32_t PIXEL_MAP_RGB888_BYTE = 3; static constexpr int32_t PIXEL_MAP_ARGB8888_BYTE = 4; +static constexpr int32_t PIXEL_MAP_BIG_TEST_WIDTH = 4 * 1024; +static constexpr int32_t PIXEL_MAP_BIG_TEST_HEIGHT = 3 * 100; class ImagePixelMapTest : public testing::Test { public: @@ -48,7 +50,13 @@ public: int32_t rowDataSize = pixelMapWidth; uint32_t bufferSize = rowDataSize * pixelMapHeight; + if (bufferSize <= 0) { + return nullptr; + } void *buffer = malloc(bufferSize); + if (buffer == nullptr) { + return nullptr; + } char *ch = (char *)buffer; for (unsigned int i = 0; i < bufferSize; i++) { *(ch++) = (char)i; @@ -61,8 +69,8 @@ public: std::unique_ptr ConstructBigPixmap() { - int32_t pixelMapWidth = 4 * 1024; - int32_t pixelMapHeight = 3 * 100; + int32_t pixelMapWidth = PIXEL_MAP_BIG_TEST_WIDTH; + int32_t pixelMapHeight = PIXEL_MAP_BIG_TEST_HEIGHT; std::unique_ptr pixelMap = std::make_unique(); ImageInfo info; info.size.width = pixelMapWidth; @@ -545,6 +553,7 @@ HWTEST_F(ImagePixelMapTest, ImagePixelMap013, TestSize.Level3) Parcel data; std::unique_ptr pixelmap1 = ConstructBigPixmap(); + EXPECT_NE(pixelmap1, nullptr); GTEST_LOG_(INFO) << "ImagePixelMap013 ConstructPixmap success"; bool ret = pixelmap1.get()->Marshalling(data); GTEST_LOG_(INFO) << "ImagePixelMap013 Marshalling success"; @@ -561,10 +570,9 @@ HWTEST_F(ImagePixelMapTest, ImagePixelMap013, TestSize.Level3) EXPECT_EQ(pixelmap1->GetPixelFormat(), pixelmap2->GetPixelFormat()); GTEST_LOG_(INFO) << "ImagePixelMap013 GetPixelFormat success"; EXPECT_EQ(pixelmap1->GetColorSpace(), pixelmap2->GetColorSpace()); - GTEST_LOG_(INFO) << "ImagePixelMap013 GetColorSpace success"; + GTEST_LOG_(INFO) << "ImagePixelMap013 GetColorSpace success"; EXPECT_EQ(true, pixelmap1->IsSameImage(*pixelmap2)); GTEST_LOG_(INFO) << "ImagePixelMapTest: ImagePixelMap013 end"; } - } // namespace Multimedia } // namespace OHOS \ No newline at end of file diff --git a/interfaces/innerkits/include/pixel_map.h b/interfaces/innerkits/include/pixel_map.h index 40b4fdf84..270dc20e6 100644 --- a/interfaces/innerkits/include/pixel_map.h +++ b/interfaces/innerkits/include/pixel_map.h @@ -167,11 +167,11 @@ private: static void ReleaseMemory(AllocatorType allocType, void *addr, void *context, uint32_t size); static bool WriteImageData(Parcel &parcel, const void *data, size_t size); - static uint8_t *ReadImageData(Parcel &parcel, size_t size); - + static uint8_t *ReadImageData(Parcel &parcel, int32_t size); static int ReadFileDescriptor(Parcel &parcel); - static bool WriteFileDescriptor(Parcel &parcel, int fd); + bool ReadImageInfo(Parcel &parcel, ImageInfo &imgInfo); + bool WriteImageInfo(Parcel &parcel) const; uint8_t *data_ = nullptr; // this info SHOULD be the final info for decoded pixelmap, not the original image info -- Gitee From 2c62f246eda9a428d823d6eedd8e7d31fb1f0cbd Mon Sep 17 00:00:00 2001 From: caochuan Date: Tue, 12 Oct 2021 10:53:27 +0800 Subject: [PATCH 3/8] Fix code check issue(2) Signed-off-by: caochuan --- .../innerkitsimpl/common/src/pixel_map.cpp | 29 +++++++++---------- .../test/unittest/image_pixel_map_test.cpp | 10 +++++-- interfaces/innerkits/include/pixel_map.h | 2 +- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/frameworks/innerkitsimpl/common/src/pixel_map.cpp b/frameworks/innerkitsimpl/common/src/pixel_map.cpp index b1d08ffed..66a556a7a 100644 --- a/frameworks/innerkitsimpl/common/src/pixel_map.cpp +++ b/frameworks/innerkitsimpl/common/src/pixel_map.cpp @@ -26,7 +26,6 @@ #include "parcel.h" #ifndef _WIN32 #include "securec.h" -#include "ipc_file_descriptor.h" #else #include "memory.h" #endif @@ -34,6 +33,7 @@ #if !defined(_WIN32) && !defined(_APPLE) #include #include "ashmem.h" +#include "ipc_file_descriptor.h" #endif namespace OHOS { @@ -1055,8 +1055,13 @@ void PixelMap::ReleaseMemory(AllocatorType allocType, void *addr, void *context, } } -bool PixelMap::WriteImageData(Parcel &parcel, const void *data, size_t size) +bool PixelMap::WriteImageData(Parcel &parcel, size_t size) const { + const uint8_t *data = data_; + if (data == nullptr) { + HiLog::Error(LABEL, "write to parcel failed, pixel memory is null."); + return false; + } if (data == nullptr || size > MAX_IMAGEDATA_SIZE) { return false; } @@ -1107,7 +1112,6 @@ uint8_t *PixelMap::ReadImageData(Parcel &parcel, int32_t bufferSize) { uint8_t *base = nullptr; int fd = -1; - AllocatorType allocType = AllocatorType::HEAP_ALLOC; if (static_cast(bufferSize) <= MIN_IMAGEDATA_SIZE) { const uint8_t *ptr = parcel.ReadUnpadBuffer(bufferSize); @@ -1128,7 +1132,6 @@ uint8_t *PixelMap::ReadImageData(Parcel &parcel, int32_t bufferSize) } } else { #if !defined(_WIN32) && !defined(_APPLE) - allocType = AllocatorType::SHARE_MEM_ALLOC; fd = ReadFileDescriptor(parcel); if (fd < 0) { HiLog::Error(LABEL, "read fd :[%{public}d] error", fd); @@ -1156,7 +1159,7 @@ uint8_t *PixelMap::ReadImageData(Parcel &parcel, int32_t bufferSize) return nullptr; } - ReleaseMemory(allocType, ptr, &fd, bufferSize); + ReleaseMemory(AllocatorType::SHARE_MEM_ALLOC, ptr, &fd, bufferSize); #endif } @@ -1222,7 +1225,8 @@ bool PixelMap::Marshalling(Parcel &parcel) const { int32_t PIXEL_MAP_INFO_MAX_LENGTH = 128; int32_t bufferSize = rowDataSize_ * imageInfo_.size.height; - + HiLog::Error(LABEL, "+++++++++++++++++bufferSize:[%{public}d]", bufferSize); + HiLog::Error(LABEL, "+++++++++++++++++parcel.GetDataCapacity:[%{public}d]", parcel.GetDataCapacity()); if (static_cast(bufferSize + PIXEL_MAP_INFO_MAX_LENGTH) > parcel.GetDataCapacity() && !parcel.SetDataCapacity(bufferSize + PIXEL_MAP_INFO_MAX_LENGTH)) { HiLog::Error(LABEL, "set parcel max capacity:[%{public}d] failed.", bufferSize + PIXEL_MAP_INFO_MAX_LENGTH); @@ -1253,12 +1257,8 @@ bool PixelMap::Marshalling(Parcel &parcel) const } #endif } else { - const uint8_t *addr = data_; - if (addr == nullptr) { - HiLog::Error(LABEL, "write to parcel failed, pixel memory is null."); - return false; - } - if (!WriteImageData(parcel, addr, bufferSize)) { + + if (!WriteImageData(parcel, bufferSize)) { HiLog::Error(LABEL, "write pixel map buffer to parcel failed."); return false; } @@ -1286,12 +1286,11 @@ PixelMap *PixelMap::Unmarshalling(Parcel &parcel) { PixelMap *pixelMap = new PixelMap(); if (pixelMap == nullptr) { - HiLog::Error(LABEL, "create pixelmap pointer fail"); return nullptr; } ImageInfo imgInfo; - if (!pixelMap->ReadImageInfo(parcel,imgInfo)) { + if (!pixelMap->ReadImageInfo(parcel, imgInfo)) { HiLog::Error(LABEL, "read imageInfo fail"); return nullptr; } @@ -1307,7 +1306,6 @@ PixelMap *PixelMap::Unmarshalling(Parcel &parcel) HiLog::Error(LABEL, "fd < 0"); return nullptr; } - HiLog::Debug(LABEL, "ReadFileDescriptor fd %{public}d.", fd); void* ptr = ::mmap(nullptr, bufferSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (ptr == MAP_FAILED) { ::close(fd); @@ -1316,7 +1314,6 @@ PixelMap *PixelMap::Unmarshalling(Parcel &parcel) } context = new int32_t(); if (context == nullptr) { - HiLog::Error(LABEL, "alloc context error."); ::munmap(ptr, bufferSize); ::close(fd); return nullptr; diff --git a/frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp b/frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp index c2f56d82a..dc3fd6dc0 100644 --- a/frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp @@ -27,8 +27,8 @@ static constexpr int32_t PIXEL_MAP_TEST_HEIGHT = 3; static constexpr int32_t PIXEL_MAP_RGB565_BYTE = 2; static constexpr int32_t PIXEL_MAP_RGB888_BYTE = 3; static constexpr int32_t PIXEL_MAP_ARGB8888_BYTE = 4; -static constexpr int32_t PIXEL_MAP_BIG_TEST_WIDTH = 4 * 1024; -static constexpr int32_t PIXEL_MAP_BIG_TEST_HEIGHT = 3 * 100; +constexpr int32_t PIXEL_MAP_BIG_TEST_WIDTH = 4 * 1024; +constexpr int32_t PIXEL_MAP_BIG_TEST_HEIGHT = 3 * 100; class ImagePixelMapTest : public testing::Test { public: @@ -80,7 +80,13 @@ public: pixelMap->SetImageInfo(info); int32_t bufferSize = pixelMap->GetByteCount(); + if (bufferSize <= 0) { + return nullptr; + } void *buffer = malloc(bufferSize); + if (buffer == nullptr) { + return nullptr; + } char *ch = (char *)buffer; for (int32_t i = 0; i < bufferSize; i++) { *(ch++) = 'a'; diff --git a/interfaces/innerkits/include/pixel_map.h b/interfaces/innerkits/include/pixel_map.h index 270dc20e6..eccacc2ab 100644 --- a/interfaces/innerkits/include/pixel_map.h +++ b/interfaces/innerkits/include/pixel_map.h @@ -166,7 +166,7 @@ private: } static void ReleaseMemory(AllocatorType allocType, void *addr, void *context, uint32_t size); - static bool WriteImageData(Parcel &parcel, const void *data, size_t size); + bool WriteImageData(Parcel &parcel, size_t size) const; static uint8_t *ReadImageData(Parcel &parcel, int32_t size); static int ReadFileDescriptor(Parcel &parcel); static bool WriteFileDescriptor(Parcel &parcel, int fd); -- Gitee From 4d8da9945f5c821dfda0dd90daa7db3d07b029d0 Mon Sep 17 00:00:00 2001 From: caochuan Date: Tue, 12 Oct 2021 14:22:05 +0800 Subject: [PATCH 4/8] Fix code check issue(3) Signed-off-by: caochuan --- frameworks/innerkitsimpl/common/src/pixel_map.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/frameworks/innerkitsimpl/common/src/pixel_map.cpp b/frameworks/innerkitsimpl/common/src/pixel_map.cpp index 66a556a7a..e5d3b9050 100644 --- a/frameworks/innerkitsimpl/common/src/pixel_map.cpp +++ b/frameworks/innerkitsimpl/common/src/pixel_map.cpp @@ -1225,14 +1225,12 @@ bool PixelMap::Marshalling(Parcel &parcel) const { int32_t PIXEL_MAP_INFO_MAX_LENGTH = 128; int32_t bufferSize = rowDataSize_ * imageInfo_.size.height; - HiLog::Error(LABEL, "+++++++++++++++++bufferSize:[%{public}d]", bufferSize); - HiLog::Error(LABEL, "+++++++++++++++++parcel.GetDataCapacity:[%{public}d]", parcel.GetDataCapacity()); - if (static_cast(bufferSize + PIXEL_MAP_INFO_MAX_LENGTH) > parcel.GetDataCapacity() && + if (static_cast(bufferSize) <= MIN_IMAGEDATA_SIZE && + static_cast(bufferSize + PIXEL_MAP_INFO_MAX_LENGTH) > parcel.GetDataCapacity() && !parcel.SetDataCapacity(bufferSize + PIXEL_MAP_INFO_MAX_LENGTH)) { HiLog::Error(LABEL, "set parcel max capacity:[%{public}d] failed.", bufferSize + PIXEL_MAP_INFO_MAX_LENGTH); return false; } - if (!WriteImageInfo(parcel)) { HiLog::Error(LABEL, "write image info to parcel failed."); return false; @@ -1257,7 +1255,6 @@ bool PixelMap::Marshalling(Parcel &parcel) const } #endif } else { - if (!WriteImageData(parcel, bufferSize)) { HiLog::Error(LABEL, "write pixel map buffer to parcel failed."); return false; -- Gitee From 3c139c08d09d67a55ea9788f8d19666c9f5259cb Mon Sep 17 00:00:00 2001 From: caochuan Date: Tue, 12 Oct 2021 16:03:59 +0800 Subject: [PATCH 5/8] Fix plugin ut issue Signed-off-by: caochuan --- .../formatagentplugin/src/plugin_export.cpp | 23 ++++++++++++++++++- .../image/libgifplugin/src/plugin_export.cpp | 22 +++++++++++++++++- .../image/libheifplugin/src/plugin_export.cpp | 22 +++++++++++++++++- .../image/libjpegplugin/src/plugin_export.cpp | 22 +++++++++++++++++- .../image/libpngplugin/src/plugin_export.cpp | 22 +++++++++++++++++- .../image/libwebpplugin/src/plugin_export.cpp | 22 +++++++++++++++++- .../plugin_example2/plugin_export.cpp | 23 ++++++++++++++++++- .../plugin_example3/plugin_export.cpp | 23 ++++++++++++++++++- 8 files changed, 171 insertions(+), 8 deletions(-) diff --git a/plugins/common/libs/image/formatagentplugin/src/plugin_export.cpp b/plugins/common/libs/image/formatagentplugin/src/plugin_export.cpp index 9b8071909..9216f85a2 100644 --- a/plugins/common/libs/image/formatagentplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/formatagentplugin/src/plugin_export.cpp @@ -41,6 +41,7 @@ PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::RawFormatAgent) PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::WbmpFormatAgent) PLUGIN_EXPORT_REGISTER_CLASS_END +using std::string; using namespace OHOS::HiviewDFX; static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibImageFormatAgent" }; @@ -51,4 +52,24 @@ static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibIm // define the external interface of this plugin. PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP() -// PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() +OHOS::MultimediaPlugin::PluginClassBase *PluginExternalCreate(const string &className) +{ + HiLog::Debug(LABEL, "PluginExternalCreate: create object for package: %{public}s, class: %{public}s.", + PACKAGE_NAME.c_str(), className.c_str()); + + auto iter = implClassMap.find(className); + if (iter == implClassMap.end()) { + HiLog::Error(LABEL, "PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.", + className.c_str(), PACKAGE_NAME.c_str()); + return nullptr; + } + + auto creator = iter->second; + if (creator == nullptr) { + HiLog::Error(LABEL, "PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.", + className.c_str(), PACKAGE_NAME.c_str()); + return nullptr; + } + + return creator(); +} \ No newline at end of file diff --git a/plugins/common/libs/image/libgifplugin/src/plugin_export.cpp b/plugins/common/libs/image/libgifplugin/src/plugin_export.cpp index 549b117b5..41f1b3950 100644 --- a/plugins/common/libs/image/libgifplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/libgifplugin/src/plugin_export.cpp @@ -37,4 +37,24 @@ static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibGi // define the external interface of this plugin. PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP() -// PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() +OHOS::MultimediaPlugin::PluginClassBase *PluginExternalCreate(const string &className) +{ + HiLog::Debug(LABEL, "PluginExternalCreate: create object for package: %{public}s, class: %{public}s.", + PACKAGE_NAME.c_str(), className.c_str()); + + auto iter = implClassMap.find(className); + if (iter == implClassMap.end()) { + HiLog::Error(LABEL, "PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.", + className.c_str(), PACKAGE_NAME.c_str()); + return nullptr; + } + + auto creator = iter->second; + if (creator == nullptr) { + HiLog::Error(LABEL, "PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.", + className.c_str(), PACKAGE_NAME.c_str()); + return nullptr; + } + + return creator(); +} diff --git a/plugins/common/libs/image/libheifplugin/src/plugin_export.cpp b/plugins/common/libs/image/libheifplugin/src/plugin_export.cpp index 9e32a2164..478bdf3e2 100644 --- a/plugins/common/libs/image/libheifplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/libheifplugin/src/plugin_export.cpp @@ -37,4 +37,24 @@ static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibHe // define the external interface of this plugin. PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP() -// PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() +OHOS::MultimediaPlugin::PluginClassBase *PluginExternalCreate(const string &className) +{ + HiLog::Debug(LABEL, "PluginExternalCreate: create object for package: %{public}s, class: %{public}s.", + PACKAGE_NAME.c_str(), className.c_str()); + + auto iter = implClassMap.find(className); + if (iter == implClassMap.end()) { + HiLog::Error(LABEL, "PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.", + className.c_str(), PACKAGE_NAME.c_str()); + return nullptr; + } + + auto creator = iter->second; + if (creator == nullptr) { + HiLog::Error(LABEL, "PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.", + className.c_str(), PACKAGE_NAME.c_str()); + return nullptr; + } + + return creator(); +} diff --git a/plugins/common/libs/image/libjpegplugin/src/plugin_export.cpp b/plugins/common/libs/image/libjpegplugin/src/plugin_export.cpp index bac59e55e..8fc74bd2e 100644 --- a/plugins/common/libs/image/libjpegplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/libjpegplugin/src/plugin_export.cpp @@ -41,4 +41,24 @@ static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibJp // define the external interface of this plugin. PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP() -// PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() +OHOS::MultimediaPlugin::PluginClassBase *PluginExternalCreate(const string &className) +{ + HiLog::Debug(LABEL, "PluginExternalCreate: create object for package: %{public}s, class: %{public}s.", + PACKAGE_NAME.c_str(), className.c_str()); + + auto iter = implClassMap.find(className); + if (iter == implClassMap.end()) { + HiLog::Error(LABEL, "PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.", + className.c_str(), PACKAGE_NAME.c_str()); + return nullptr; + } + + auto creator = iter->second; + if (creator == nullptr) { + HiLog::Error(LABEL, "PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.", + className.c_str(), PACKAGE_NAME.c_str()); + return nullptr; + } + + return creator(); +} diff --git a/plugins/common/libs/image/libpngplugin/src/plugin_export.cpp b/plugins/common/libs/image/libpngplugin/src/plugin_export.cpp index d9409b280..208a2b42f 100644 --- a/plugins/common/libs/image/libpngplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/libpngplugin/src/plugin_export.cpp @@ -37,4 +37,24 @@ static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibPn // define the external interface of this plugin. PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP() -// PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() +OHOS::MultimediaPlugin::PluginClassBase *PluginExternalCreate(const string &className) +{ + HiLog::Debug(LABEL, "PluginExternalCreate: create object for package: %{public}s, class: %{public}s.", + PACKAGE_NAME.c_str(), className.c_str()); + + auto iter = implClassMap.find(className); + if (iter == implClassMap.end()) { + HiLog::Error(LABEL, "PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.", + className.c_str(), PACKAGE_NAME.c_str()); + return nullptr; + } + + auto creator = iter->second; + if (creator == nullptr) { + HiLog::Error(LABEL, "PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.", + className.c_str(), PACKAGE_NAME.c_str()); + return nullptr; + } + + return creator(); +} diff --git a/plugins/common/libs/image/libwebpplugin/src/plugin_export.cpp b/plugins/common/libs/image/libwebpplugin/src/plugin_export.cpp index 571590925..8524c3c9b 100644 --- a/plugins/common/libs/image/libwebpplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/libwebpplugin/src/plugin_export.cpp @@ -37,4 +37,24 @@ static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibWe // define the external interface of this plugin. PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP() -// PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() +OHOS::MultimediaPlugin::PluginClassBase *PluginExternalCreate(const string &className) +{ + HiLog::Debug(LABEL, "PluginExternalCreate: create object for package: %{public}s, class: %{public}s.", + PACKAGE_NAME.c_str(), className.c_str()); + + auto iter = implClassMap.find(className); + if (iter == implClassMap.end()) { + HiLog::Error(LABEL, "PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.", + className.c_str(), PACKAGE_NAME.c_str()); + return nullptr; + } + + auto creator = iter->second; + if (creator == nullptr) { + HiLog::Error(LABEL, "PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.", + className.c_str(), PACKAGE_NAME.c_str()); + return nullptr; + } + + return creator(); +} diff --git a/plugins/manager/test/unittest/common/plugin_example/plugin_example2/plugin_export.cpp b/plugins/manager/test/unittest/common/plugin_example/plugin_example2/plugin_export.cpp index 761ae7c4d..e84edc0fa 100644 --- a/plugins/manager/test/unittest/common/plugin_example/plugin_example2/plugin_export.cpp +++ b/plugins/manager/test/unittest/common/plugin_example/plugin_example2/plugin_export.cpp @@ -30,6 +30,7 @@ PLUGIN_EXPORT_REGISTER_CLASS(OHOS::PluginExample::LabelDetector2) PLUGIN_EXPORT_REGISTER_CLASS(OHOS::PluginExample::CloudLabelDetector2) PLUGIN_EXPORT_REGISTER_CLASS_END +using std::string; using namespace OHOS::HiviewDFX; static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "plugin_example2" }; @@ -40,5 +41,25 @@ static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "plugi // define the external interface of this plugin PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP() -// PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() +OHOS::MultimediaPlugin::PluginClassBase *PluginExternalCreate(const string &className) +{ + HiLog::Debug(LABEL, "PluginExternalCreate: create object for package: %{public}s, class: %{public}s.", + PACKAGE_NAME.c_str(), className.c_str()); + + auto iter = implClassMap.find(className); + if (iter == implClassMap.end()) { + HiLog::Error(LABEL, "PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.", + className.c_str(), PACKAGE_NAME.c_str()); + return nullptr; + } + + auto creator = iter->second; + if (creator == nullptr) { + HiLog::Error(LABEL, "PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.", + className.c_str(), PACKAGE_NAME.c_str()); + return nullptr; + } + + return creator(); +} diff --git a/plugins/manager/test/unittest/common/plugin_example/plugin_example3/plugin_export.cpp b/plugins/manager/test/unittest/common/plugin_example/plugin_example3/plugin_export.cpp index 0205a53f3..a7c8c1cb8 100644 --- a/plugins/manager/test/unittest/common/plugin_example/plugin_example3/plugin_export.cpp +++ b/plugins/manager/test/unittest/common/plugin_example/plugin_example3/plugin_export.cpp @@ -30,6 +30,7 @@ PLUGIN_EXPORT_REGISTER_CLASS(OHOS::PluginExample::LabelDetector3) PLUGIN_EXPORT_REGISTER_CLASS(OHOS::PluginExample::CloudLabelDetector3) PLUGIN_EXPORT_REGISTER_CLASS_END +using std::string; using namespace OHOS::HiviewDFX; static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "plugin_example3" }; @@ -40,5 +41,25 @@ static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "plugi // define the external interface of this plugin PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() PLUGIN_EXPORT_DEFAULT_EXTERNAL_STOP() -// PLUGIN_EXPORT_DEFAULT_EXTERNAL_CREATE() +OHOS::MultimediaPlugin::PluginClassBase *PluginExternalCreate(const string &className) +{ + HiLog::Debug(LABEL, "PluginExternalCreate: create object for package: %{public}s, class: %{public}s.", + PACKAGE_NAME.c_str(), className.c_str()); + + auto iter = implClassMap.find(className); + if (iter == implClassMap.end()) { + HiLog::Error(LABEL, "PluginExternalCreate: failed to find class: %{public}s, in package: %{public}s.", + className.c_str(), PACKAGE_NAME.c_str()); + return nullptr; + } + + auto creator = iter->second; + if (creator == nullptr) { + HiLog::Error(LABEL, "PluginExternalCreate: null creator for class: %{public}s, in package: %{public}s.", + className.c_str(), PACKAGE_NAME.c_str()); + return nullptr; + } + + return creator(); +} -- Gitee From a02edec7c14f62be69f8c2da41043a8f1a43a70a Mon Sep 17 00:00:00 2001 From: caochuan Date: Tue, 12 Oct 2021 17:21:14 +0800 Subject: [PATCH 6/8] Fix plugin code check issue Signed-off-by: caochuan --- .../common/libs/image/formatagentplugin/src/plugin_export.cpp | 4 ++-- plugins/common/libs/image/libgifplugin/src/plugin_export.cpp | 4 ++-- plugins/common/libs/image/libheifplugin/src/plugin_export.cpp | 4 ++-- plugins/common/libs/image/libpngplugin/src/plugin_export.cpp | 4 ++-- plugins/common/libs/image/libwebpplugin/src/plugin_export.cpp | 1 + .../common/plugin_example/plugin_example2/plugin_export.cpp | 4 ++-- .../common/plugin_example/plugin_example3/plugin_export.cpp | 4 ++-- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/plugins/common/libs/image/formatagentplugin/src/plugin_export.cpp b/plugins/common/libs/image/formatagentplugin/src/plugin_export.cpp index 9216f85a2..8dffc6374 100644 --- a/plugins/common/libs/image/formatagentplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/formatagentplugin/src/plugin_export.cpp @@ -46,8 +46,8 @@ using namespace OHOS::HiviewDFX; static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibImageFormatAgent" }; -#define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__); -#define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__); +#define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__) +#define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__) // define the external interface of this plugin. PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() diff --git a/plugins/common/libs/image/libgifplugin/src/plugin_export.cpp b/plugins/common/libs/image/libgifplugin/src/plugin_export.cpp index 41f1b3950..5acfd0b91 100644 --- a/plugins/common/libs/image/libgifplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/libgifplugin/src/plugin_export.cpp @@ -31,8 +31,8 @@ using namespace OHOS::HiviewDFX; static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibGifPlugin" }; -#define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__); -#define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__); +#define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__) +#define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__) // define the external interface of this plugin. PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() diff --git a/plugins/common/libs/image/libheifplugin/src/plugin_export.cpp b/plugins/common/libs/image/libheifplugin/src/plugin_export.cpp index 478bdf3e2..137c60d49 100644 --- a/plugins/common/libs/image/libheifplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/libheifplugin/src/plugin_export.cpp @@ -31,8 +31,8 @@ using namespace OHOS::HiviewDFX; static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibHeifPlugin" }; -#define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__); -#define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__); +#define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__) +#define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__) // define the external interface of this plugin. PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() diff --git a/plugins/common/libs/image/libpngplugin/src/plugin_export.cpp b/plugins/common/libs/image/libpngplugin/src/plugin_export.cpp index 208a2b42f..7f5ff87e9 100644 --- a/plugins/common/libs/image/libpngplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/libpngplugin/src/plugin_export.cpp @@ -31,8 +31,8 @@ using namespace OHOS::HiviewDFX; static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibPngPlugin" }; -#define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__); -#define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__); +#define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__) +#define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__) // define the external interface of this plugin. PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() diff --git a/plugins/common/libs/image/libwebpplugin/src/plugin_export.cpp b/plugins/common/libs/image/libwebpplugin/src/plugin_export.cpp index 8524c3c9b..6aff46f50 100644 --- a/plugins/common/libs/image/libwebpplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/libwebpplugin/src/plugin_export.cpp @@ -27,6 +27,7 @@ PLUGIN_EXPORT_REGISTER_CLASS_BEGIN PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::WebpDecoder) PLUGIN_EXPORT_REGISTER_CLASS_END +using std::string; using namespace OHOS::HiviewDFX; static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibWebpPlugin" }; diff --git a/plugins/manager/test/unittest/common/plugin_example/plugin_example2/plugin_export.cpp b/plugins/manager/test/unittest/common/plugin_example/plugin_example2/plugin_export.cpp index e84edc0fa..49a794f8e 100644 --- a/plugins/manager/test/unittest/common/plugin_example/plugin_example2/plugin_export.cpp +++ b/plugins/manager/test/unittest/common/plugin_example/plugin_example2/plugin_export.cpp @@ -35,8 +35,8 @@ using namespace OHOS::HiviewDFX; static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "plugin_example2" }; -#define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__); -#define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__); +#define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__) +#define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__) // define the external interface of this plugin PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() diff --git a/plugins/manager/test/unittest/common/plugin_example/plugin_example3/plugin_export.cpp b/plugins/manager/test/unittest/common/plugin_example/plugin_example3/plugin_export.cpp index a7c8c1cb8..140a32c87 100644 --- a/plugins/manager/test/unittest/common/plugin_example/plugin_example3/plugin_export.cpp +++ b/plugins/manager/test/unittest/common/plugin_example/plugin_example3/plugin_export.cpp @@ -35,8 +35,8 @@ using namespace OHOS::HiviewDFX; static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "plugin_example3" }; -#define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__); -#define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__); +#define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__) +#define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__) // define the external interface of this plugin PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() -- Gitee From 5418a4c7b6062539c3997f0918aaf3357180063b Mon Sep 17 00:00:00 2001 From: caochuan Date: Tue, 12 Oct 2021 17:21:52 +0800 Subject: [PATCH 7/8] Fix code check issue(4) Signed-off-by: caochuan --- frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp b/frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp index dc3fd6dc0..cbd34f6fd 100644 --- a/frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/image_pixel_map_test.cpp @@ -83,7 +83,7 @@ public: if (bufferSize <= 0) { return nullptr; } - void *buffer = malloc(bufferSize); + std::unique_ptr buffer = malloc(bufferSize); if (buffer == nullptr) { return nullptr; } -- Gitee From 7a28332a8708a04a334378084e7c87638fe79aae Mon Sep 17 00:00:00 2001 From: caochuan Date: Wed, 13 Oct 2021 10:30:23 +0800 Subject: [PATCH 8/8] Fix plugin code check issue Signed-off-by: caochuan --- plugins/common/libs/image/libgifplugin/src/plugin_export.cpp | 1 + plugins/common/libs/image/libheifplugin/src/plugin_export.cpp | 1 + plugins/common/libs/image/libjpegplugin/src/plugin_export.cpp | 1 + plugins/common/libs/image/libpngplugin/src/plugin_export.cpp | 1 + plugins/common/libs/image/libwebpplugin/src/plugin_export.cpp | 4 ++-- 5 files changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/common/libs/image/libgifplugin/src/plugin_export.cpp b/plugins/common/libs/image/libgifplugin/src/plugin_export.cpp index 5acfd0b91..fa33cb82b 100644 --- a/plugins/common/libs/image/libgifplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/libgifplugin/src/plugin_export.cpp @@ -27,6 +27,7 @@ PLUGIN_EXPORT_REGISTER_CLASS_BEGIN PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::GifDecoder) PLUGIN_EXPORT_REGISTER_CLASS_END +using std::string; using namespace OHOS::HiviewDFX; static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibGifPlugin" }; diff --git a/plugins/common/libs/image/libheifplugin/src/plugin_export.cpp b/plugins/common/libs/image/libheifplugin/src/plugin_export.cpp index 137c60d49..2fd74a5ed 100644 --- a/plugins/common/libs/image/libheifplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/libheifplugin/src/plugin_export.cpp @@ -27,6 +27,7 @@ PLUGIN_EXPORT_REGISTER_CLASS_BEGIN PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::HeifDecoder) PLUGIN_EXPORT_REGISTER_CLASS_END +using std::string; using namespace OHOS::HiviewDFX; static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibHeifPlugin" }; diff --git a/plugins/common/libs/image/libjpegplugin/src/plugin_export.cpp b/plugins/common/libs/image/libjpegplugin/src/plugin_export.cpp index 8fc74bd2e..cac9d197d 100644 --- a/plugins/common/libs/image/libjpegplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/libjpegplugin/src/plugin_export.cpp @@ -31,6 +31,7 @@ PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::JpegEncoder) #endif PLUGIN_EXPORT_REGISTER_CLASS_END +using std::string; using namespace OHOS::HiviewDFX; static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibJpegPlugin" }; diff --git a/plugins/common/libs/image/libpngplugin/src/plugin_export.cpp b/plugins/common/libs/image/libpngplugin/src/plugin_export.cpp index 7f5ff87e9..edcf6aec8 100644 --- a/plugins/common/libs/image/libpngplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/libpngplugin/src/plugin_export.cpp @@ -27,6 +27,7 @@ PLUGIN_EXPORT_REGISTER_CLASS_BEGIN PLUGIN_EXPORT_REGISTER_CLASS(OHOS::ImagePlugin::PngDecoder) PLUGIN_EXPORT_REGISTER_CLASS_END +using std::string; using namespace OHOS::HiviewDFX; static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibPngPlugin" }; diff --git a/plugins/common/libs/image/libwebpplugin/src/plugin_export.cpp b/plugins/common/libs/image/libwebpplugin/src/plugin_export.cpp index 6aff46f50..4c7072f4b 100644 --- a/plugins/common/libs/image/libwebpplugin/src/plugin_export.cpp +++ b/plugins/common/libs/image/libwebpplugin/src/plugin_export.cpp @@ -32,8 +32,8 @@ using namespace OHOS::HiviewDFX; static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_TAG_DOMAIN_ID_PLUGIN, "LibWebpPlugin" }; -#define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__); -#define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__); +#define PLUGIN_LOG_D(...) HiLog::Debug(LABEL, __VA_ARGS__) +#define PLUGIN_LOG_E(...) HiLog::Error(LABEL, __VA_ARGS__) // define the external interface of this plugin. PLUGIN_EXPORT_DEFAULT_EXTERNAL_START() -- Gitee