From c99839aa66059ace0a19ed11bcb2ecaa95300bde Mon Sep 17 00:00:00 2001 From: peilixia Date: Thu, 27 Oct 2022 11:57:14 +0000 Subject: [PATCH] fixed 494fd97 from https://gitee.com/peilixia/commonlibrary_c_utils/pulls/135 ICSL modify Signed-off-by: peilixia --- base/src/event_reactor.cpp | 3 --- base/src/parcel.cpp | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/base/src/event_reactor.cpp b/base/src/event_reactor.cpp index e54d183..ea53837 100644 --- a/base/src/event_reactor.cpp +++ b/base/src/event_reactor.cpp @@ -95,9 +95,6 @@ uint32_t EventReactor::ScheduleTimer(const TimerCallback& cb, uint32_t interval, { std::lock_guard lock(mutex_); std::shared_ptr handler = std::make_shared(this, interval, once); - if (handler == nullptr) { - return TIMER_ERR_INVALID_VALUE; - } handler->SetTimerCallback(cb); uint32_t ret = handler->Initialize(); if (ret != TIMER_ERR_OK) { diff --git a/base/src/parcel.cpp b/base/src/parcel.cpp index ae218ee..441a4df 100644 --- a/base/src/parcel.cpp +++ b/base/src/parcel.cpp @@ -964,8 +964,8 @@ const std::string Parcel::ReadString() return std::string(); } - size_t readCapacity = dataLength + 1; - if ((readCapacity > (size_t)dataLength) && (readCapacity <= GetReadableBytes())) { + size_t readCapacity = static_cast(dataLength) + 1; + if (readCapacity <= GetReadableBytes()) { const uint8_t *dest = ReadBuffer(readCapacity); if (dest != nullptr) { const auto *str = reinterpret_cast(dest); @@ -990,8 +990,8 @@ bool Parcel::ReadString(std::string &value) return false; } - size_t readCapacity = dataLength + 1; - if ((readCapacity > (size_t)dataLength) && (readCapacity <= GetReadableBytes())) { + size_t readCapacity = static_cast(dataLength) + 1; + if (readCapacity <= GetReadableBytes()) { const uint8_t *dest = ReadBuffer(readCapacity); if (dest != nullptr) { const auto *str = reinterpret_cast(dest); @@ -1017,8 +1017,8 @@ const std::u16string Parcel::ReadString16() return std::u16string(); } - size_t readCapacity = (dataLength + 1) * sizeof(char16_t); - if ((readCapacity > (size_t)dataLength) && (readCapacity <= GetReadableBytes())) { + size_t readCapacity = (static_cast(dataLength) + 1) * sizeof(char16_t); + if ((readCapacity > (static_cast(dataLength))) && (readCapacity <= GetReadableBytes())) { const uint8_t *str = ReadBuffer(readCapacity); if (str != nullptr) { const auto *u16Str = reinterpret_cast(str); @@ -1043,7 +1043,7 @@ bool Parcel::ReadString16(std::u16string &value) return false; } - size_t readCapacity = (dataLength + 1) * sizeof(char16_t); + size_t readCapacity = (static_cast(dataLength) + 1) * sizeof(char16_t); if (readCapacity <= GetReadableBytes()) { const uint8_t *str = ReadBuffer(readCapacity); if (str != nullptr) { @@ -1075,8 +1075,8 @@ const std::u16string Parcel::ReadString16WithLength(int32_t &readLength) return std::u16string(); } - size_t readCapacity = (dataLength + 1) * sizeof(char16_t); - if ((readCapacity > (size_t)dataLength) && (readCapacity <= GetReadableBytes())) { + size_t readCapacity = (static_cast(dataLength) + 1) * sizeof(char16_t); + if ((readCapacity > (static_cast(dataLength))) && (readCapacity <= GetReadableBytes())) { const uint8_t *str = ReadBuffer(readCapacity); if (str != nullptr) { const auto *u16Str = reinterpret_cast(str); @@ -1106,8 +1106,8 @@ const std::string Parcel::ReadString8WithLength(int32_t &readLength) return std::string(); } - size_t readCapacity = (dataLength + 1) * sizeof(char); - if ((readCapacity > (size_t)dataLength) && (readCapacity <= GetReadableBytes())) { + size_t readCapacity = (static_cast(dataLength) + 1) * sizeof(char); + if (readCapacity <= GetReadableBytes()) { const uint8_t *str = ReadBuffer(readCapacity); if (str != nullptr) { const auto *u8Str = reinterpret_cast(str); -- Gitee