From d759f8df9dbf8eb6d26b85825385312d5d11f8bf Mon Sep 17 00:00:00 2001 From: superldy Date: Thu, 24 Feb 2022 15:40:45 +0800 Subject: [PATCH] Signed-off-by:lidanyang Signed-off-by: superldy --- interfaces/kits/misc_info/misc_info.cpp | 4 +-- interfaces/kits/updaterkits/updaterkits.cpp | 2 +- services/applypatch/block_set.cpp | 4 +-- services/applypatch/raw_writer.cpp | 6 ++-- services/applypatch/store.cpp | 9 +++--- services/applypatch/transfer_manager.cpp | 4 +-- services/diffpatch/bzip2/bzip2_adapter.cpp | 2 +- services/diffpatch/bzip2/lz4_adapter.cpp | 4 +-- services/diffpatch/diff/blocks_diff.cpp | 4 +-- services/diffpatch/diff/image_diff.cpp | 12 +++---- services/diffpatch/diffpatch.cpp | 7 ++-- services/diffpatch/patch/blocks_patch.cpp | 14 ++++---- services/diffpatch/patch/image_patch.cpp | 10 +++--- services/diffpatch/patch/update_patch.cpp | 2 +- services/flashd/blockdevice.h | 2 +- services/flashd/daemon/daemon.cpp | 12 ++++--- services/flashd/daemon/daemon_unity.cpp | 2 +- services/flashd/daemon/daemon_updater.cpp | 4 +-- services/flashd/daemon/flashd_main.cpp | 2 +- services/flashd/flash_service.cpp | 2 +- services/flashd/host/host_updater.cpp | 16 +++++----- services/flashd/partition.cpp | 12 +++---- services/fs_manager/partitions.cpp | 8 ++--- .../package/pkg_algorithm/pkg_algo_lz4.cpp | 32 +++++++++---------- .../package/pkg_algorithm/pkg_algo_sign.cpp | 7 ++-- .../package/pkg_manager/pkg_managerImpl.cpp | 16 +++++----- services/package/pkg_manager/pkg_stream.cpp | 13 ++++---- services/package/pkg_manager/pkg_utils.cpp | 6 ++-- services/package/pkg_package/pkg_gzipfile.h | 2 +- .../package/pkg_package/pkg_upgradefile.cpp | 2 +- services/package/pkg_package/pkg_zipfile.cpp | 6 ++-- .../script_basicinstruction.cpp | 2 +- .../script_interpreter/script_scanner.cpp | 2 +- .../script_manager/script_managerImpl.cpp | 2 +- services/ui/animation_label.cpp | 3 +- services/ui/drm_driver.cpp | 3 +- services/ui/frame.cpp | 2 +- services/ui/progress_bar.cpp | 10 +++--- services/ui/text_label.cpp | 19 +++++------ services/ui/view.cpp | 13 ++++---- services/ui/view.h | 2 +- .../updater_binary/update_image_block.cpp | 2 +- services/updater_binary/update_partitions.cpp | 23 +++++++++---- services/updater_main.cpp | 3 +- services/updater_utils.cpp | 6 ++-- .../applypatch_test/all_cmd_unittest.cpp | 2 +- .../applypatch_test/applypatch_unittest.cpp | 2 +- .../applypatch_test/imagepatch_unittest.cpp | 4 +-- .../unittest/diffpatch/diffpatch_unittest.cpp | 2 +- .../flashd_test/flash_host_unittest.cpp | 17 +++++----- .../flashd_test/flash_service_unittest.cpp | 18 ++++++----- test/unittest/package/package_unittest.cpp | 2 +- test/unittest/package/pkg_algo_unittest.cpp | 6 ++-- .../unittest/package/pkg_manager_unittest.cpp | 6 ++-- .../unittest/package/pkg_package_unittest.cpp | 2 +- test/unittest/package/pkg_test.h | 2 +- test/unittest/script/threadpool_unittest.cpp | 2 +- .../updater_binary_unittest.cpp | 4 +-- test/unittest/utils/utils_unittest.cpp | 6 ++-- utils/include/utils.h | 2 +- utils/utils.cpp | 14 ++++---- 61 files changed, 217 insertions(+), 194 deletions(-) diff --git a/interfaces/kits/misc_info/misc_info.cpp b/interfaces/kits/misc_info/misc_info.cpp index cf40c7f4..fe208f6e 100755 --- a/interfaces/kits/misc_info/misc_info.cpp +++ b/interfaces/kits/misc_info/misc_info.cpp @@ -32,7 +32,7 @@ bool WriteUpdaterMessage(const std::string &path, const UpdateMessage &boot) size_t ret = fwrite(&boot, sizeof(UpdateMessage), 1, fp); UPDATER_FILE_CHECK(ret == 1, "WriteUpdaterMessage fwrite failed", fclose(fp); return false); - ret = fclose(fp); + ret = static_cast(fclose(fp)); UPDATER_FILE_CHECK(ret == 0, "WriteUpdaterMessage fclose failed", return false); return true; } @@ -50,7 +50,7 @@ bool ReadUpdaterMessage(const std::string &path, UpdateMessage &boot) UPDATER_FILE_CHECK(ret == 1, "ReadUpdaterMessage fwrite failed", fclose(fp); return false); ret = fclose(fp); - UPDATER_FILE_CHECK(ret == 0, "ReadUpdaterMessage fclose failed", return false); + UPDATER_FILE_CHECK(static_cast(ret) == 0, "ReadUpdaterMessage fclose failed", return false); UPDATER_FILE_CHECK(!memcpy_s(&boot, sizeof(UpdateMessage), &tempBoot, sizeof(UpdateMessage)), "ReadUpdaterMessage memcpy failed", return false); return true; diff --git a/interfaces/kits/updaterkits/updaterkits.cpp b/interfaces/kits/updaterkits/updaterkits.cpp index bfc2a6a4..1dfe765d 100755 --- a/interfaces/kits/updaterkits/updaterkits.cpp +++ b/interfaces/kits/updaterkits/updaterkits.cpp @@ -36,7 +36,7 @@ static bool WriteToMiscAndRebootToUpdater(const std::string &miscFile, return false; } #ifndef UPDATER_UT - int32_t propertyMaxSize = 92; + size_t propertyMaxSize = 92; char updateCmd[propertyMaxSize]; void(snprintf_s(updateCmd, propertyMaxSize, propertyMaxSize - 1, "reboot,updater:%s", updateMsg.update)); bool bRet = OHOS::system::SetParameter("ohos.startup.powerctrl", updateCmd); diff --git a/services/applypatch/block_set.cpp b/services/applypatch/block_set.cpp index b267cfb7..52c2646e 100644 --- a/services/applypatch/block_set.cpp +++ b/services/applypatch/block_set.cpp @@ -132,7 +132,7 @@ size_t BlockSet::ReadDataFromBlock(int fd, std::vector &buffer) for (; it != blocks_.end(); ++it) { ret = lseek64(fd, static_cast(it->first * H_BLOCK_SIZE), SEEK_SET); UPDATER_ERROR_CHECK(ret != -1, "Fail to seek", return -1); - size_t size = (it->second - it->first) * H_BLOCK_SIZE; + ssize_t size = static_cast(it->second - it->first) * H_BLOCK_SIZE; UPDATER_ERROR_CHECK(utils::ReadFully(fd, buffer.data() + pos, size), "Fail to read", return -1); pos += size; } @@ -263,7 +263,7 @@ int32_t BlockSet::LoadTargetBuffer(const Command &cmd, std::vector &buf int res = stat(storePath.c_str(), &storeStat); if (VerifySha256(buffer, blockSize, srcHash) == 0) { if (isOverlap && res != 0) { - ret = Store::WriteDataToStore(storeBase, srcHash, buffer, blockSize * H_BLOCK_SIZE); + ret = Store::WriteDataToStore(storeBase, srcHash, buffer, static_cast(blockSize) * H_BLOCK_SIZE); UPDATER_ERROR_CHECK(ret == 0, "failed to stash overlapping source blocks", return -1); } return 0; diff --git a/services/applypatch/raw_writer.cpp b/services/applypatch/raw_writer.cpp index 0e30d6ce..d91699d9 100644 --- a/services/applypatch/raw_writer.cpp +++ b/services/applypatch/raw_writer.cpp @@ -46,18 +46,18 @@ bool RawWriter::Write(const uint8_t *addr, size_t len, WriteMode mode, const std int RawWriter::WriteInternal(int fd, const uint8_t *data, size_t len) { ssize_t written = 0; - size_t rest = len; + ssize_t rest = len; int ret = lseek64(fd, offset_, SEEK_SET); UPDATER_FILE_CHECK(ret != -1, "RawWriter: failed to seek file to " << offset_, return -1); while (rest > 0) { - written = write(fd, data, rest); + written = write(fd, data, static_cast(rest)); UPDATER_FILE_CHECK(written >= 0, "RawWriter: failed to write data of len " << len, return -1); data += written; rest -= written; } - offset_ += len; + offset_ += static_cast(len); return 0; } } // namespace updater diff --git a/services/applypatch/store.cpp b/services/applypatch/store.cpp index d436ec53..a2434cfc 100644 --- a/services/applypatch/store.cpp +++ b/services/applypatch/store.cpp @@ -82,7 +82,7 @@ int32_t Store::CreateNewSpace(const std::string &path, bool needClear) int32_t Store::WriteDataToStore(const std::string &dirPath, const std::string &fileName, const std::vector &buffer, int size) { - UPDATER_CHECK_ONLY_RETURN(!dirPath.empty(), return -1); + UPDATER_CHECK_ONLY_RETURN(!dirPath.empty() && size > 0, return -1); std::string pathTmp; if (!fileName.empty()) { pathTmp = dirPath + "/"; @@ -95,7 +95,7 @@ int32_t Store::WriteDataToStore(const std::string &dirPath, const std::string &f UPDATER_ERROR_CHECK(fchown(fd, O_USER_GROUP_ID, O_USER_GROUP_ID) == 0, "Failed to chown", close(fd); return -1); LOG(INFO) << "Writing " << size << " blocks to " << path; - if (!WriteFully(fd, const_cast(buffer.data()), size)) { + if (!WriteFully(fd, const_cast(buffer.data()), static_cast(size))) { UPDATER_CHECK_ONLY_RETURN(errno != EIO, close(fd); return 1); LOG(ERROR) << "Write to stash failed"; close(fd); @@ -119,11 +119,12 @@ int32_t Store::LoadDataFromStore(const std::string &dirPath, const std::string & } struct stat fileStat {}; UPDATER_WARING_CHECK(stat(path.c_str(), &fileStat) != -1, "Failed to stat", return -1); - UPDATER_ERROR_CHECK((fileStat.st_size % H_BLOCK_SIZE) == 0, "Not multiple of block size 4096", return -1); + UPDATER_ERROR_CHECK((fileStat.st_size % H_BLOCK_SIZE) == 0 && fileStat.st_size >= 0, + "Not multiple of block size 4096", return -1); int fd = open(path.c_str(), O_RDONLY); UPDATER_ERROR_CHECK(fd != -1, "Failed to create", return -1); - buffer.resize(fileStat.st_size); + buffer.resize(static_cast(fileStat.st_size)); UPDATER_ERROR_CHECK(ReadFully(fd, buffer.data(), fileStat.st_size), "Failed to read store data", close(fd); fd = -1; return -1); close(fd); diff --git a/services/applypatch/transfer_manager.cpp b/services/applypatch/transfer_manager.cpp index 6ba2e13d..f0d5fdf7 100644 --- a/services/applypatch/transfer_manager.cpp +++ b/services/applypatch/transfer_manager.cpp @@ -64,7 +64,7 @@ bool TransferManager::CommandsParser(int fd, const std::vector &con retryCmd = ReloadForRetry(); } std::unique_ptr cmd; - int initBlock = 0; + size_t initBlock = 0; while (ct != context.end()) { cmd = std::make_unique(); UPDATER_ERROR_CHECK(cmd != nullptr, "Failed to parse command line.", return false); @@ -93,7 +93,7 @@ bool TransferManager::CommandsParser(int fd, const std::vector &con } if (totalSize != 0 && globalParams->env != nullptr && NeedSetProgress(cmd->GetCommandType())) { globalParams->env->PostMessage("set_progress", - std::to_string((float)(globalParams->written - initBlock) / totalSize)); + std::to_string(((float)globalParams->written - initBlock) / totalSize)); } LOG(INFO) << "Running command : " << cmd->GetArgumentByPos(0) << " success"; } diff --git a/services/diffpatch/bzip2/bzip2_adapter.cpp b/services/diffpatch/bzip2/bzip2_adapter.cpp index 509f3eac..7960b07e 100644 --- a/services/diffpatch/bzip2/bzip2_adapter.cpp +++ b/services/diffpatch/bzip2/bzip2_adapter.cpp @@ -109,7 +109,7 @@ int32_t BZip2StreamAdapter::WriteData(const BlockBuffer &srcData) do { ret = BZ2_bzCompress(&stream_, BZ_RUN); if (stream_.avail_out == 0) { - outStream_.write(buffer_.data(), buffer_.size()); + outStream_.write(buffer_.data(), static_cast(buffer_.size())); dataSize_ += stream_.next_out - reinterpret_cast(buffer_.data()); stream_.avail_out = buffer_.size(); stream_.next_out = reinterpret_cast(buffer_.data()); diff --git a/services/diffpatch/bzip2/lz4_adapter.cpp b/services/diffpatch/bzip2/lz4_adapter.cpp index 6f59e8a2..c6365b40 100644 --- a/services/diffpatch/bzip2/lz4_adapter.cpp +++ b/services/diffpatch/bzip2/lz4_adapter.cpp @@ -49,7 +49,7 @@ int32_t Lz4FrameAdapter::Open() PATCH_CHECK(!LZ4F_isError(errorCode), return -1, "Failed to create compress context %s", LZ4F_getErrorName(errorCode)); PATCH_CHECK(!memset_s(&preferences, sizeof(preferences), 0, sizeof(preferences)), return -1, "Memset failed"); - preferences.autoFlush = autoFlush_; + preferences.autoFlush = static_cast(autoFlush_); preferences.compressionLevel = compressionLevel_; preferences.frameInfo.blockMode = ((blockIndependence_ == 0) ? LZ4F_blockLinked : LZ4F_blockIndependent); preferences.frameInfo.blockSizeID = (LZ4F_blockSizeID_t)blockSizeID_; @@ -167,7 +167,7 @@ int32_t Lz4BlockAdapter::Open() blockSize, LZ4_BLOCK_SIZE(blockSizeID_), LZ4B_BLOCK_SIZE); /* write package */ - size_t bufferSize = LZ4_compressBound(LZ4_BLOCK_SIZE(blockSizeID_)); + size_t bufferSize = static_cast(LZ4_compressBound(LZ4_BLOCK_SIZE(blockSizeID_))); buffer_.resize(bufferSize); int32_t ret = memcpy_s(buffer_.data(), buffer_.size(), &LZ4B_MAGIC_NUMBER, sizeof(int32_t)); PATCH_CHECK(ret == 0, return -1, "Failed to memcpy "); diff --git a/services/diffpatch/diff/blocks_diff.cpp b/services/diffpatch/diff/blocks_diff.cpp index 2a68f28c..735ef1e9 100644 --- a/services/diffpatch/diff/blocks_diff.cpp +++ b/services/diffpatch/diff/blocks_diff.cpp @@ -26,7 +26,7 @@ namespace updatepatch { #define SWAP(a, b) auto swapTmp = (a); (a) = (b); (b) = swapTmp #define MIN(x, y) (((x) < (y)) ? (x) : (y)) #define SET_BUFFER(y, buffer, index) \ - (buffer)[index] = (y) % 256; (y) -= (buffer)[index]; (y) = (y) / 256 + (buffer)[index] = static_cast((y) % 256); (y) -= (buffer)[index]; (y) = (y) / 256 constexpr uint32_t BUCKET_SIZE = 256; constexpr uint32_t MULTIPLE_TWO = 2; @@ -193,7 +193,7 @@ int32_t BlocksStreamDiff::WritePatchHeader(int64_t controlSize, { PATCH_DEBUG("WritePatchHeader %zu", static_cast(stream_.tellp())); stream_.seekp(offset_, std::ios::beg); - stream_.write(BSDIFF_MAGIC.c_str(), BSDIFF_MAGIC.size()); + stream_.write(BSDIFF_MAGIC.c_str(), static_cast(BSDIFF_MAGIC.size())); PkgBuffer buffer(sizeof(int64_t)); WriteLE64(buffer, controlSize); stream_.write(reinterpret_cast(buffer.buffer), sizeof(int64_t)); diff --git a/services/diffpatch/diff/image_diff.cpp b/services/diffpatch/diff/image_diff.cpp index bbc7277a..8f28ffaa 100644 --- a/services/diffpatch/diff/image_diff.cpp +++ b/services/diffpatch/diff/image_diff.cpp @@ -29,7 +29,7 @@ constexpr int32_t MAX_NEW_LENGTH = 1 << 20; template static void WriteToFile(std::ofstream &patchFile, DataType data, size_t dataSize) { - patchFile.write(reinterpret_cast(&data), dataSize); + patchFile.write(reinterpret_cast(&data), static_cast(dataSize)); } static size_t GetHeaderSize(const ImageBlock &block) @@ -127,7 +127,7 @@ int32_t ImageDiff::WriteHeader(std::ofstream &patchFile, static_cast(patchFile.tellp()), dataOffset, block.newInfo.length); WriteToFile(patchFile, static_cast(block.newInfo.length), sizeof(int32_t)); patchFile.write(reinterpret_cast(block.newInfo.buffer + block.newInfo.start), - block.newInfo.length); + static_cast(block.newInfo.length)); BlockBuffer rawData = { block.newInfo.buffer + block.newInfo.start, block.newInfo.length }; PATCH_LOGI("WriteHeader BLOCK_ROW hash %zu %s", block.newInfo.length, GeneraterBufferHash(rawData).c_str()); @@ -161,13 +161,13 @@ int32_t ImageDiff::MakeBlockPatch(ImageBlock &block, std::fstream &blockPatchFil int32_t ImageDiff::WritePatch(std::ofstream &patchFile, std::fstream &blockPatchFile) { if (usePatchFile_) { // copy to patch - size_t bsPatchSize = static_cast(blockPatchFile.tellp()); - PATCH_LOGI("WritePatch patch block patch %zu img patch offset %zu", + int bsPatchSize = blockPatchFile.tellp(); + PATCH_LOGI("WritePatch patch block patch %d img patch offset %zu", bsPatchSize, static_cast(patchFile.tellp())); blockPatchFile.seekg(0, std::ios::beg); std::vector buffer(IGMDIFF_LIMIT_UNIT); while (bsPatchSize > 0) { - size_t readLen = (bsPatchSize > IGMDIFF_LIMIT_UNIT) ? IGMDIFF_LIMIT_UNIT : bsPatchSize; + int readLen = (bsPatchSize > IGMDIFF_LIMIT_UNIT) ? static_cast(IGMDIFF_LIMIT_UNIT) : bsPatchSize; blockPatchFile.read(buffer.data(), readLen); patchFile.write(buffer.data(), readLen); bsPatchSize -= readLen; @@ -193,7 +193,7 @@ int32_t ImageDiff::DiffImage(const std::string &patchName) std::ofstream patchFile(patchName, std::ios::out | std::ios::trunc | std::ios::binary); PATCH_CHECK(!patchFile.fail(), return -1, "Failed to open %s", patchName.c_str()); - patchFile.write(PKGDIFF_MAGIC.c_str(), PKGDIFF_MAGIC.size()); + patchFile.write(PKGDIFF_MAGIC.c_str(), static_cast(PKGDIFF_MAGIC.size())); size_t dataOffset = PKGDIFF_MAGIC.size(); uint32_t size = static_cast(updateBlocks_.size()); patchFile.write(reinterpret_cast(&size), sizeof(uint32_t)); diff --git a/services/diffpatch/diffpatch.cpp b/services/diffpatch/diffpatch.cpp index 36b48f5c..5cf8315f 100644 --- a/services/diffpatch/diffpatch.cpp +++ b/services/diffpatch/diffpatch.cpp @@ -27,7 +27,7 @@ int32_t WriteDataToFile(const std::string &fileName, const std::vector { std::ofstream patchFile(fileName, std::ios::out | std::ios::binary); PATCH_CHECK(patchFile, return -1, "Failed to open %s", fileName.c_str()); - patchFile.write(reinterpret_cast(data.data()), dataSize); + patchFile.write(reinterpret_cast(data.data()), static_cast(dataSize)); patchFile.close(); return PATCH_SUCCESS; } @@ -40,9 +40,10 @@ int32_t PatchMapFile(const std::string &fileName, MemMapInfo &info) int32_t ret = fstat(file, &st); PATCH_CHECK(ret >= 0, close(file); return ret, "Failed to fstat"); - info.memory = static_cast(mmap(nullptr, st.st_size, PROT_READ, MAP_PRIVATE, file, 0)); + info.memory = static_cast(mmap(nullptr, static_cast(st.st_size), PROT_READ, + MAP_PRIVATE, file, 0)); PATCH_CHECK(info.memory != nullptr, close(file); return -1, "Failed to memory map"); - info.length = st.st_size; + info.length = static_cast(st.st_size); close(file); return PATCH_SUCCESS; } diff --git a/services/diffpatch/patch/blocks_patch.cpp b/services/diffpatch/patch/blocks_patch.cpp index ec60d149..db7a43fe 100644 --- a/services/diffpatch/patch/blocks_patch.cpp +++ b/services/diffpatch/patch/blocks_patch.cpp @@ -120,9 +120,9 @@ int32_t BlocksPatch::ReadHeader(int64_t &controlDataSize, int64_t &diffDataSize, BlockBuffer patchBuffer = {header, patchInfo_.length - patchInfo_.start}; controlDataReader_.reset(new BZip2BufferReadAdapter(offset, static_cast(controlDataSize), patchBuffer)); - offset += controlDataSize; + offset += static_cast(controlDataSize); diffDataReader_.reset(new BZip2BufferReadAdapter(offset, static_cast(diffDataSize), patchBuffer)); - offset += diffDataSize; + offset += static_cast(diffDataSize); extraDataReader_.reset(new BZip2BufferReadAdapter(offset, patchInfo_.length - patchInfo_.start - offset, patchBuffer)); PATCH_CHECK(controlDataReader_ != nullptr && diffDataReader_ != nullptr && extraDataReader_ != nullptr, @@ -154,7 +154,7 @@ int32_t BlocksBufferPatch::ReadHeader(int64_t &controlDataSize, int64_t &diffDat int32_t ret = BlocksPatch::ReadHeader(controlDataSize, diffDataSize, newSize); PATCH_CHECK(ret == 0, return -1, "Failed to read header"); PATCH_LOGI("ReadHeader controlDataSize: %ld %ld %ld", controlDataSize, diffDataSize, newSize); - newData_.resize(newSize); + newData_.resize(static_cast(newSize)); return 0; } @@ -196,7 +196,7 @@ int32_t BlocksStreamPatch::RestoreDiffData(const ControlData &ctrlData) int32_t ret = diffDataReader_->ReadData(diffBuffer); PATCH_CHECK(ret == 0, return ret, "Failed to read diff data"); - size_t oldOffset = oldOffset_; + int64_t oldOffset = oldOffset_; size_t oldLength = stream_->GetFileLength(); PkgBuffer buffer {}; if (stream_->GetStreamType() == PkgStream::PkgStreamType_MemoryMap || @@ -206,7 +206,7 @@ int32_t BlocksStreamPatch::RestoreDiffData(const ControlData &ctrlData) } else { std::vector oldData(ctrlData.diffLength); size_t readLen = 0; - ret = stream_->Read(buffer, oldOffset_, ctrlData.diffLength, readLen); + ret = stream_->Read(buffer, static_cast(oldOffset_), ctrlData.diffLength, readLen); PATCH_CHECK(ret == 0 && readLen == static_cast(ctrlData.diffLength), return ret, "Failed to get old buffer"); oldOffset = 0; @@ -217,7 +217,7 @@ int32_t BlocksStreamPatch::RestoreDiffData(const ControlData &ctrlData) } } // write - return writer_->Write(newOffset_, diffBuffer, static_cast(ctrlData.diffLength)); + return writer_->Write(static_cast(newOffset_), diffBuffer, static_cast(ctrlData.diffLength)); } int32_t BlocksStreamPatch::RestoreExtraData(const ControlData &ctrlData) @@ -230,6 +230,6 @@ int32_t BlocksStreamPatch::RestoreExtraData(const ControlData &ctrlData) int32_t ret = extraDataReader_->ReadData(extraBuffer); PATCH_CHECK(ret == 0, return ret, "Failed to read extra data"); // write - return writer_->Write(newOffset_, extraBuffer, static_cast(ctrlData.extraLength)); + return writer_->Write(static_cast(newOffset_), extraBuffer, static_cast(ctrlData.extraLength)); } } // namespace updatepatch diff --git a/services/diffpatch/patch/image_patch.cpp b/services/diffpatch/patch/image_patch.cpp index e7357344..503d03a3 100644 --- a/services/diffpatch/patch/image_patch.cpp +++ b/services/diffpatch/patch/image_patch.cpp @@ -232,11 +232,11 @@ std::unique_ptr Lz4ImagePatch::GetFileInfo() const fileInfo->fileInfo.packedSize = 0; fileInfo->fileInfo.unpackedSize = 0; fileInfo->fileInfo.identity = std::to_string(g_tmpFileId++); - fileInfo->compressionLevel = static_cast(compressionLevel_); - fileInfo->blockIndependence = static_cast(blockIndependence_); - fileInfo->contentChecksumFlag = static_cast(contentChecksumFlag_); - fileInfo->blockSizeID = static_cast(blockSizeID_); - fileInfo->autoFlush = static_cast(autoFlush_); + fileInfo->compressionLevel = static_cast(compressionLevel_); + fileInfo->blockIndependence = static_cast(blockIndependence_); + fileInfo->contentChecksumFlag = static_cast(contentChecksumFlag_); + fileInfo->blockSizeID = static_cast(blockSizeID_); + fileInfo->autoFlush = static_cast(autoFlush_); return std::unique_ptr((FileInfo *)fileInfo); } diff --git a/services/diffpatch/patch/update_patch.cpp b/services/diffpatch/patch/update_patch.cpp index db8276c3..bde0d0dc 100644 --- a/services/diffpatch/patch/update_patch.cpp +++ b/services/diffpatch/patch/update_patch.cpp @@ -227,7 +227,7 @@ int32_t FilePatchWriter::Write(size_t start, const BlockBuffer &buffer, size_t l stream_.open(newFileName_, std::ios::out | std::ios::binary); PATCH_CHECK(!stream_.fail(), return -1, "Failed to open %s", newFileName_.c_str()); } - stream_.write(reinterpret_cast(buffer.buffer), len); + stream_.write(reinterpret_cast(buffer.buffer), static_cast(len)); return 0; } diff --git a/services/flashd/blockdevice.h b/services/flashd/blockdevice.h index 3533a586..7d28c157 100755 --- a/services/flashd/blockdevice.h +++ b/services/flashd/blockdevice.h @@ -41,7 +41,7 @@ private: std::string ReadDeviceSysInfo(const std::string &type); std::string devPath_; - size_t devSize_ = 0; + long int devSize_ = 0; size_t sectorSize_ = 0; // logical sector size size_t physSectorSize_ = 0; // physical sector size DeviceType type_ = DeviceType::DEVICE_UNKNOWN; diff --git a/services/flashd/daemon/daemon.cpp b/services/flashd/daemon/daemon.cpp index d3e1d09b..198544c4 100755 --- a/services/flashd/daemon/daemon.cpp +++ b/services/flashd/daemon/daemon.cpp @@ -120,7 +120,8 @@ bool HdcDaemon::RedirectToTask(HTaskInfo hTaskInfo, HSession hSession, const uin break; default: std::string info = "Command not support in flashd\n"; - Send(hSession->sessionId, channelId, CMD_KERNEL_ECHO_RAW, (uint8_t *)info.data(), info.size()); + Send(hSession->sessionId, channelId, CMD_KERNEL_ECHO_RAW, (uint8_t *)info.data(), + static_cast(info.size())); uint8_t count = 1; Send(hSession->sessionId, channelId, CMD_KERNEL_CHANNEL_CLOSE, &count, 1); break; @@ -149,7 +150,8 @@ bool HdcDaemon::HandDaemonAuth(HSession hSession, const uint32_t channelId, Sess handshake.authType = AUTH_TOKEN; handshake.buf = hSession->tokenRSA; string bufString = SerialStruct::SerializeToString(handshake); - Send(hSession->sessionId, channelId, CMD_KERNEL_HANDSHAKE, (uint8_t *)bufString.c_str(), bufString.size()); + Send(hSession->sessionId, channelId, CMD_KERNEL_HANDSHAKE, (uint8_t *)bufString.c_str(), + static_cast(bufString.size())); ret = true; break; } @@ -162,13 +164,13 @@ bool HdcDaemon::HandDaemonAuth(HSession hSession, const uint32_t channelId, Sess // device locally, and the signature authentication will be correct when the subsequent connection is // connected. if (!HdcAuth::AuthVerify((uint8_t *)hSession->tokenRSA.c_str(), - (uint8_t *)handshake.buf.c_str(), handshake.buf.size())) { + (uint8_t *)handshake.buf.c_str(), static_cast(handshake.buf.size()))) { // Next auth handshake.authType = AUTH_TOKEN; handshake.buf = hSession->tokenRSA; string bufString = SerialStruct::SerializeToString(handshake); Send(hSession->sessionId, channelId, CMD_KERNEL_HANDSHAKE, (uint8_t *)bufString.c_str(), - bufString.size()); + static_cast(bufString.size())); break; } ret = true; @@ -297,6 +299,6 @@ void HdcDaemon::JdwpNewFileDescriptor(const uint8_t *buf, const int bytesIO) { uint32_t pid = *(uint32_t *)(buf + 1); uint32_t fd = *(uint32_t *)(buf + 5); // 5 : fd offset - ((HdcJdwp *)clsJdwp)->SendJdwpNewFD(pid, fd); + ((HdcJdwp *)clsJdwp)->SendJdwpNewFD(pid, static_cast(fd)); }; } // namespace Hdc diff --git a/services/flashd/daemon/daemon_unity.cpp b/services/flashd/daemon/daemon_unity.cpp index cd4f3ffe..6ccb319d 100755 --- a/services/flashd/daemon/daemon_unity.cpp +++ b/services/flashd/daemon/daemon_unity.cpp @@ -58,7 +58,7 @@ bool HdcDaemonUnity::AsyncCmdOut(bool finish, int64_t exitStatus, const string r --refCount; break; } - if (!SendToAnother(currentDataCommand, (uint8_t *)result.c_str(), result.size())) { + if (!SendToAnother(currentDataCommand, (uint8_t *)result.c_str(), static_cast(result.size()))) { break; } ret = true; diff --git a/services/flashd/daemon/daemon_updater.cpp b/services/flashd/daemon/daemon_updater.cpp index 2e84fe75..7c5f8529 100755 --- a/services/flashd/daemon/daemon_updater.cpp +++ b/services/flashd/daemon/daemon_updater.cpp @@ -171,7 +171,7 @@ void DaemonUpdater::AsyncUpdateFinish(uint8_t type, int32_t retCode, const strin { WRITE_LOG(LOG_DEBUG, "AsyncUpdateFinish retCode %d result %s", retCode, result.c_str()); uint32_t percentage = (retCode != 0) ? flashd::PERCENT_CLEAR : flashd::PERCENT_FINISH; - SendToAnother(CMD_UPDATER_PROGRESS, (uint8_t *)&percentage, sizeof(uint32_t)); + SendToAnother(CMD_UPDATER_PROGRESS, (uint8_t *)&percentage, static_cast(sizeof(uint32_t))); (void)flashd::DoUpdaterFinish(flashHandle_, type, ctxNow.localPath); string echo = result; @@ -184,7 +184,7 @@ void DaemonUpdater::AsyncUpdateFinish(uint8_t type, int32_t retCode, const strin vecBuf.push_back(MSG_OK); } vecBuf.insert(vecBuf.end(), (uint8_t *)echo.c_str(), (uint8_t *)echo.c_str() + echo.size()); - SendToAnother(CMD_UPDATER_FINISH, vecBuf.data(), vecBuf.size()); + SendToAnother(CMD_UPDATER_FINISH, vecBuf.data(), static_cast(vecBuf.size())); } #ifdef UPDATER_UT diff --git a/services/flashd/daemon/flashd_main.cpp b/services/flashd/daemon/flashd_main.cpp index f5270bc2..4ec2c170 100755 --- a/services/flashd/daemon/flashd_main.cpp +++ b/services/flashd/daemon/flashd_main.cpp @@ -35,7 +35,7 @@ int flashd_main(int argc, char **argv) int logLevel = atoi(arg.c_str() + strlen("-l")); FLASHDAEMON_CHECK(!(logLevel < 0 || logLevel > LOG_LAST), logLevel = LOG_LAST, "Loglevel error %d", logLevel); - Base::SetLogLevel(logLevel); + Base::SetLogLevel(static_cast(logLevel)); } else if (arg.find("-t") != std::string::npos || strncmp(modeSet, "tcp", 3) == 0) { // 3 tcp enableTcp = true; } else if (arg.find("-u") != std::string::npos) { diff --git a/services/flashd/flash_service.cpp b/services/flashd/flash_service.cpp index c5050ba0..294ae4fb 100755 --- a/services/flashd/flash_service.cpp +++ b/services/flashd/flash_service.cpp @@ -94,7 +94,7 @@ int FlashService::DoUpdate(const std::string &packageName) ret = updater::ExecUpdate(pkgManager, 0, [&](const char *cmd, const char *content) { if (strncmp(cmd, "data", strlen(cmd)) == 0) { - size_t dataLen = std::stoll(content); + size_t dataLen = std::stoul(content); PostProgress(UPDATEMOD_UPDATE, dataLen, nullptr); } }); diff --git a/services/flashd/host/host_updater.cpp b/services/flashd/host/host_updater.cpp index 0b4cd69b..a0578c0f 100755 --- a/services/flashd/host/host_updater.cpp +++ b/services/flashd/host/host_updater.cpp @@ -99,8 +99,8 @@ bool HostUpdater::BeginTransfer(CtxFile &context, std::string HostUpdater::GetFileName(const std::string &fileName) const { - int32_t pos = fileName.find_last_of('/'); - if (pos < 0) { // win32 + std::size_t pos = fileName.find_last_of('/'); + if (pos == std::string::npos) { // win32 pos = fileName.find_last_of('\\'); } return fileName.substr(pos + 1, fileName.size()); @@ -129,7 +129,7 @@ void HostUpdater::CheckMaster(CtxFile *context) int ret = memcpy_s(buffer.data(), buffer.size(), &realSize, sizeof(realSize)); int ret2 = memcpy_s(buffer.data() + sizeof(realSize), buffer.size(), bufString.c_str(), bufString.size()); if ((ret == 0) && (ret2 == 0)) { - SendToAnother(CMD_UPDATER_CHECK, (uint8_t *)buffer.data(), buffer.size()); + SendToAnother(CMD_UPDATER_CHECK, (uint8_t *)buffer.data(), static_cast(buffer.size())); } } @@ -169,7 +169,7 @@ bool HostUpdater::CommandDispatch(const uint16_t command, uint8_t *payload, cons case CMD_UPDATER_BEGIN: { std::string s("Processing: 0%%"); sendProgress = true; - SendRawData(reinterpret_cast(s.data()), s.size()); + SendRawData(reinterpret_cast(s.data()), static_cast(s.size())); break; } case CMD_UPDATER_UPDATE_INIT: @@ -220,8 +220,8 @@ void HostUpdater::ProcessProgress(uint32_t percentage) const int bufferSize = 128; std::vector buffer(bufferSize); if (percentage == PERCENT_CLEAR) { // clear - SendRawData(reinterpret_cast(backStr.data()), backStr.size()); - SendRawData(reinterpret_cast(breakStr.data()), breakStr.size()); + SendRawData(reinterpret_cast(backStr.data()), static_cast(backStr.size())); + SendRawData(reinterpret_cast(breakStr.data()), static_cast(breakStr.size())); sendProgress = false; return; } @@ -229,7 +229,7 @@ void HostUpdater::ProcessProgress(uint32_t percentage) HOSTUPDATER_CHECK(len > 0, return, "Failed to format progress info "); SendRawData(reinterpret_cast(buffer.data()), len); if (percentage == PERCENT_FINISH) { - SendRawData(reinterpret_cast(breakStr.data()), breakStr.size()); + SendRawData(reinterpret_cast(breakStr.data()), static_cast(breakStr.size())); sendProgress = false; } } @@ -328,7 +328,7 @@ bool HostUpdater::ConfirmCommand(const string &commandIn, bool &closeInput) continue; } if (i < minLen && isprint(c)) { - info.append(1, std::tolower(c)); + info.append(1, std::tolower(static_cast(c))); i++; } } diff --git a/services/flashd/partition.cpp b/services/flashd/partition.cpp index aa4264f0..f5c822bb 100755 --- a/services/flashd/partition.cpp +++ b/services/flashd/partition.cpp @@ -74,14 +74,14 @@ int Partition::DoFlash(const std::string &fileName) struct stat st {}; size_t fileSize = 1; if (fstat(inputFd, &st) >= 0) { - fileSize = st.st_size; + fileSize = static_cast(st.st_size); } std::vector content(BUFFER_SIZE); ssize_t readLen = read(inputFd, content.data(), content.size()); FLASHING_CHECK(readLen >= 0, close(inputFd); return FLASHING_PART_WRITE_ERROR, "Failed to flash data of len %d", readLen); - ret = WriteRowData(inputFd, fileSize, content, readLen); + ret = WriteRowData(inputFd, fileSize, content, static_cast(readLen)); close(inputFd); FLASHING_CHECK(ret == 0, return ret, "Failed to write %s", fileName.c_str()); FLASHING_LOGI("DoFlash partition %s image:%s success", partPath_.c_str(), fileName.c_str()); @@ -191,12 +191,12 @@ int Partition::Open() int Partition::WriteRowData(int inputFd, size_t fileSize, std::vector &buffer, size_t dataSize) { size_t dataLen = dataSize; - size_t totalWrite = 0; + ssize_t totalWrite = 0; do { #ifndef UPDATER_UT ssize_t writeLen = write(fd_, buffer.data(), dataLen); #else - ssize_t writeLen = dataLen; + ssize_t writeLen = static_cast(dataLen); #endif FLASHING_CHECK(writeLen >= 0, return FLASHING_PART_WRITE_ERROR, "Failed to write data of len %d", dataLen); @@ -205,8 +205,8 @@ int Partition::WriteRowData(int inputFd, size_t fileSize, std::vector & // continue read and write ssize_t ret = read(inputFd, buffer.data(), dataSize); FLASHING_CHECK(ret > 0, return -1, "Failed to read data %d %d", errno, buffer.size()); - flash_->PostProgress(UPDATEMOD_FLASH, writeLen, nullptr); - dataLen = ret; + flash_->PostProgress(UPDATEMOD_FLASH, static_cast(writeLen), nullptr); + dataLen = static_cast(ret); } while (1); fsync(fd_); return 0; diff --git a/services/fs_manager/partitions.cpp b/services/fs_manager/partitions.cpp index f965b7ee..3069106b 100644 --- a/services/fs_manager/partitions.cpp +++ b/services/fs_manager/partitions.cpp @@ -48,8 +48,8 @@ static int DeviceProbeType(BlockDevice &dev) UPDATER_CHECK_ONLY_RETURN(DeviceStat(dev, devStat), return 0); - specific->major = devMajor = major (devStat.st_rdev); - specific->minor = devMinor = minor (devStat.st_rdev); + specific->major = devMajor = static_cast(major (devStat.st_rdev)); + specific->minor = devMinor = static_cast(minor (devStat.st_rdev)); bool a1 = SCSI_BLK_MAJOR(devMajor) && (devMinor % 0x10 == 0); bool a2 = devMajor == SDMMC_MAJOR && (devMinor % 0x08 == 0); UPDATER_CHECK_ONLY_RETURN(!a1, dev.type = DEVICE_SCSI); @@ -290,10 +290,10 @@ static struct Partition* NewPartition(const BlockDevice &dev, int partn) free(part); return nullptr; } - part->start = atoi(strstart.c_str()); + part->start = static_cast(atoi(strstart.c_str())); std::string strsize = ReadPartitionFromSys(devName, partName, "size", ""); UPDATER_CHECK_ONLY_RETURN(!strsize.empty(), free(part); return nullptr); - part->length = atoi(strsize.c_str()); + part->length = static_cast(atoi(strsize.c_str())); std::string strdevname = ReadPartitionFromSys(devName, partName, "uevent", "DEVNAME="); part->devName = partName; diff --git a/services/package/pkg_algorithm/pkg_algo_lz4.cpp b/services/package/pkg_algorithm/pkg_algo_lz4.cpp index c1aa802f..a60602b5 100644 --- a/services/package/pkg_algorithm/pkg_algo_lz4.cpp +++ b/services/package/pkg_algorithm/pkg_algo_lz4.cpp @@ -46,22 +46,22 @@ int32_t PkgAlgorithmLz4::AdpLz4Compress(const uint8_t *src, uint8_t *dest, return LZ4_compress_default(reinterpret_cast(src), reinterpret_cast(dest), (int32_t)srcSize, (int32_t)dstCapacity); } - return LZ4_compress_HC(reinterpret_cast(src), reinterpret_cast(dest), srcSize, dstCapacity, - compressionLevel_); + return LZ4_compress_HC(reinterpret_cast(src), reinterpret_cast(dest), + static_cast(srcSize), static_cast(dstCapacity), compressionLevel_); } int32_t PkgAlgorithmLz4::AdpLz4Decompress(const uint8_t *src, uint8_t *dest, uint32_t srcSize, uint32_t dstCapacity) const { - return LZ4_decompress_safe(reinterpret_cast(src), reinterpret_cast(dest), srcSize, - dstCapacity); + return LZ4_decompress_safe(reinterpret_cast(src), reinterpret_cast(dest), + static_cast(srcSize), static_cast(dstCapacity)); } int32_t PkgAlgorithmBlockLz4::Pack(const PkgStreamPtr inStream, const PkgStreamPtr outStream, PkgAlgorithmContext &context) { PKG_CHECK(inStream != nullptr && outStream != nullptr, return PKG_INVALID_PARAM, "Param context null!"); - size_t blockSize = GetBlockSizeFromBlockId(blockSizeID_); + size_t blockSize = static_cast(GetBlockSizeFromBlockId(blockSizeID_)); blockSize = (blockSize > LZ4B_BLOCK_SIZE) ? LZ4B_BLOCK_SIZE : blockSize; PkgBuffer inBuffer = {blockSize}; PkgBuffer outBuffer = {LZ4_compressBound(blockSize)}; @@ -93,12 +93,12 @@ int32_t PkgAlgorithmBlockLz4::Pack(const PkgStreamPtr inStream, const PkgStreamP // Write block to buffer. // Buffer format: + - WriteLE32(outBuffer.buffer, outSize); - ret = outStream->Write(outBuffer, outSize + LZ4B_REVERSED_LEN, destOffset); + WriteLE32(outBuffer.buffer, static_cast(outSize)); + ret = outStream->Write(outBuffer, static_cast(outSize + LZ4B_REVERSED_LEN), destOffset); PKG_CHECK(ret == PKG_SUCCESS, break, "Fail write data "); srcOffset += readLen; - destOffset += outSize + LZ4B_REVERSED_LEN; + destOffset += static_cast(outSize) + LZ4B_REVERSED_LEN; } PKG_CHECK(srcOffset - context.srcOffset == context.unpackedSize, return ret, "original size error %zu %zu", srcOffset, context.unpackedSize); @@ -111,9 +111,9 @@ int32_t PkgAlgorithmBlockLz4::Unpack(const PkgStreamPtr inStream, const PkgStrea PkgAlgorithmContext &context) { PKG_CHECK(inStream != nullptr && outStream != nullptr, return PKG_INVALID_PARAM, "Param context null!"); - size_t inBuffSize = LZ4_compressBound(LZ4B_BLOCK_SIZE); + int inBuffSize = LZ4_compressBound(LZ4B_BLOCK_SIZE); PKG_CHECK(inBuffSize > 0, return PKG_NONE_MEMORY, "BufferSize must > 0"); - PkgBuffer inBuffer(inBuffSize); + PkgBuffer inBuffer((size_t)inBuffSize); PkgBuffer outBuffer(LZ4B_BLOCK_SIZE); PKG_CHECK(inBuffer.buffer != nullptr && outBuffer.buffer != nullptr, return PKG_NONE_MEMORY, "Fail to alloc buffer "); @@ -133,7 +133,7 @@ int32_t PkgAlgorithmBlockLz4::Unpack(const PkgStreamPtr inStream, const PkgStrea break; } uint32_t blockSize = ReadLE32(inBuffer.buffer); - PKG_CHECK(!(blockSize > LZ4_COMPRESSBOUND(LZ4B_BLOCK_SIZE) || blockSize > inBuffSize), break, + PKG_CHECK(!(blockSize > LZ4_COMPRESSBOUND(LZ4B_BLOCK_SIZE) || static_cast(blockSize) > inBuffSize), break, "Fail to get block size %u %u", blockSize, LZ4_COMPRESSBOUND(LZ4B_BLOCK_SIZE)); srcOffset += sizeof(uint32_t); @@ -148,9 +148,9 @@ int32_t PkgAlgorithmBlockLz4::Unpack(const PkgStreamPtr inStream, const PkgStrea PKG_CHECK(decodeSize > 0, break, "Fail to decompress"); /* Write Block */ - ret = outStream->Write(outBuffer, decodeSize, destOffset); + ret = outStream->Write(outBuffer, static_cast(decodeSize), destOffset); PKG_CHECK(ret == PKG_SUCCESS, break, "Fail write data "); - destOffset += decodeSize; + destOffset += static_cast(decodeSize); srcOffset += readLen; } context.packedSize = srcOffset - context.srcOffset; @@ -165,7 +165,7 @@ int32_t PkgAlgorithmLz4::GetPackParam(LZ4F_compressionContext_t &ctx, LZ4F_prefe errorCode = LZ4F_createCompressionContext(&ctx, LZ4F_VERSION); PKG_CHECK(!LZ4F_isError(errorCode), return PKG_NONE_MEMORY, "Fail to create compress context %s", LZ4F_getErrorName(errorCode)); - size_t blockSize = GetBlockSizeFromBlockId(blockSizeID_); + size_t blockSize = static_cast(GetBlockSizeFromBlockId(blockSizeID_)); PKG_CHECK(!memset_s(&preferences, sizeof(preferences), 0, sizeof(preferences)), return PKG_NONE_MEMORY, "Memset failed"); preferences.autoFlush = autoFlush_; @@ -303,8 +303,8 @@ int32_t PkgAlgorithmLz4::Unpack(const PkgStreamPtr inStream, const PkgStreamPtr size_t nextToRead = 0; int32_t ret = GetUnpackParam(ctx, inStream, nextToRead, srcOffset); PKG_CHECK(ret == PKG_SUCCESS, return PKG_INVALID_LZ4, "Fail to get param "); - - size_t outBuffSize = GetBlockSizeFromBlockId(blockSizeID_); + + size_t outBuffSize = static_cast(GetBlockSizeFromBlockId(blockSizeID_)); PKG_LOGI("Block size ID %d outBuffSize:%zu", blockSizeID_, outBuffSize); size_t inBuffSize = outBuffSize + sizeof(uint32_t); PKG_CHECK(inBuffSize > 0 && outBuffSize > 0, return PKG_NONE_MEMORY, "Buffer size must > 0"); diff --git a/services/package/pkg_algorithm/pkg_algo_sign.cpp b/services/package/pkg_algorithm/pkg_algo_sign.cpp index b0f9d9cc..e8876a75 100644 --- a/services/package/pkg_algorithm/pkg_algo_sign.cpp +++ b/services/package/pkg_algorithm/pkg_algo_sign.cpp @@ -47,7 +47,7 @@ int32_t SignAlgorithmRsa::SignBuffer(const PkgBuffer &buffer, std::vector(RSA_size(rsa)); signedData.resize(size); ret = 0; if (digestMethod_ == PKG_DIGEST_TYPE_SHA256) { @@ -170,8 +170,9 @@ int32_t VerifyAlgorithm::VerifyBuffer(const std::vector &digest, const ret = RSA_verify(hashNid, digest.data(), digest.size(), signature.data(), signature.size(), certs.rsa); RSA_free(certs.rsa); } else if (certs.keyType == KEY_TYPE_EC && certs.hashLen == SHA256_DIGEST_LENGTH) { - int dataLen = ReadLE32(signature.data()); - ret = ECDSA_verify(0, digest.data(), digest.size(), signature.data() + sizeof(uint32_t), dataLen, certs.ecKey); + size_t dataLen = ReadLE32(signature.data()); + ret = ECDSA_verify(0, digest.data(), static_cast(digest.size()), signature.data() + sizeof(uint32_t), + dataLen, certs.ecKey); EC_KEY_free(certs.ecKey); } X509_free(certs.cert); diff --git a/services/package/pkg_manager/pkg_managerImpl.cpp b/services/package/pkg_manager/pkg_managerImpl.cpp index aa895157..5cdafdae 100644 --- a/services/package/pkg_manager/pkg_managerImpl.cpp +++ b/services/package/pkg_manager/pkg_managerImpl.cpp @@ -494,20 +494,20 @@ void PkgManagerImpl::ClosePkgStream(PkgStreamPtr &stream) PkgFile::PkgType PkgManagerImpl::GetPkgTypeByName(const std::string &path) { - int32_t pos = path.find_last_of('.'); - if (pos < 0) { + std::size_t pos = path.find_last_of('.'); + if (pos == std::string::npos) { return PkgFile::PKG_TYPE_NONE; } - std::string postfix = path.substr(pos + 1, -1); + std::string postfix = path.substr(pos + 1); std::transform(postfix.begin(), postfix.end(), postfix.begin(), ::tolower); - if (path.substr(pos + 1, -1).compare("bin") == 0) { + if (path.substr(pos + 1).compare("bin") == 0) { return PkgFile::PKG_TYPE_UPGRADE; - } else if (path.substr(pos + 1, -1).compare("zip") == 0) { + } else if (path.substr(pos + 1).compare("zip") == 0) { return PkgFile::PKG_TYPE_ZIP; - } else if (path.substr(pos + 1, -1).compare("lz4") == 0) { + } else if (path.substr(pos + 1).compare("lz4") == 0) { return PkgFile::PKG_TYPE_LZ4; - } else if (path.substr(pos + 1, -1).compare("gz") == 0) { + } else if (path.substr(pos + 1).compare("gz") == 0) { return PkgFile::PKG_TYPE_GZIP; } return PkgFile::PKG_TYPE_NONE; @@ -526,7 +526,7 @@ int32_t PkgManagerImpl::VerifyPackage(const std::string &packagePath, const std: PKG_CHECK(fileLen > 0, ClosePkgStream(stream); return PKG_INVALID_FILE, "invalid file to load"); PkgFile::PkgType type = GetPkgTypeByName(packagePath); - int8_t digestMethod = DigestAlgorithm::GetDigestMethod(version); + uint8_t digestMethod = DigestAlgorithm::GetDigestMethod(version); size_t digestLen = DigestAlgorithm::GetDigestLen(digestMethod); size_t signatureLen = DigestAlgorithm::GetSignatureLen(digestMethod); PKG_CHECK(digestLen == digest.length, return PKG_INVALID_PARAM, "Invalid digestLen"); diff --git a/services/package/pkg_manager/pkg_stream.cpp b/services/package/pkg_manager/pkg_stream.cpp index 7f28de2f..d6bb9593 100644 --- a/services/package/pkg_manager/pkg_stream.cpp +++ b/services/package/pkg_manager/pkg_stream.cpp @@ -70,8 +70,8 @@ int32_t FileStream::Read(const PkgBuffer &data, size_t offset, size_t needRead, PKG_CHECK(data.length >= needRead, return PKG_INVALID_STREAM, "Invalid stream"); readLen = 0; size_t len = GetFileLength(); - fseek(stream_, offset, SEEK_SET); PKG_CHECK(offset <= len, return PKG_INVALID_STREAM, "Invalid offset"); + (void)fseek(stream_, static_cast(offset), SEEK_SET); len = fread(data.buffer, 1, needRead, stream_); readLen = len; return PKG_SUCCESS; @@ -81,7 +81,7 @@ int32_t FileStream::Write(const PkgBuffer &data, size_t size, size_t offset) { PKG_CHECK(streamType_ == PkgStreamType_Write, return PKG_INVALID_STREAM, "Invalid stream type"); PKG_CHECK(stream_ != nullptr, return PKG_INVALID_STREAM, "Invalid stream"); - fseek(stream_, offset, SEEK_SET); + fseek(stream_, static_cast(offset), SEEK_SET); size_t len = fwrite(data.buffer, size, 1, stream_); PKG_CHECK(len == 1, return PKG_INVALID_STREAM, "Write buffer fail"); PostDecodeProgress(POST_TYPE_DECODE_PKG, size, nullptr); @@ -134,7 +134,7 @@ int32_t MemoryMapStream::Read(const PkgBuffer &data, size_t start, size_t needRe PKG_CHECK(start <= memSize_, return PKG_INVALID_STREAM, "Invalid start"); PKG_CHECK(data.length >= needRead, return PKG_INVALID_STREAM, "Invalid start"); - MemoryMapStream::Seek(start, SEEK_SET); + MemoryMapStream::Seek(static_cast(start), SEEK_SET); size_t copyLen = GetFileLength() - start; readLen = ((copyLen > needRead) ? needRead : copyLen); PKG_CHECK(!memcpy_s(data.buffer, needRead, memMap_ + currOffset_, readLen), return PKG_NONE_MEMORY, @@ -161,16 +161,15 @@ int32_t MemoryMapStream::Seek(long int offset, int whence) if (whence == SEEK_SET) { PKG_CHECK(offset >= 0, return PKG_INVALID_STREAM, "Invalid offset"); PKG_CHECK(static_cast(offset) <= memSize_, return PKG_INVALID_STREAM, "Invalid offset"); - currOffset_ = offset; + currOffset_ = static_cast(offset); } else if (whence == SEEK_CUR) { PKG_CHECK(static_cast(offset) <= (memSize_ - currOffset_), return PKG_INVALID_STREAM, "Invalid offset"); - currOffset_ += offset; + currOffset_ += static_cast(offset); } else { PKG_CHECK(offset <= 0, return PKG_INVALID_STREAM, "Invalid offset"); PKG_CHECK((memSize_ + offset) <= memSize_, return PKG_INVALID_STREAM, "Invalid offset"); - PKG_CHECK((memSize_ + offset) >= 0, return PKG_INVALID_STREAM, "Invalid offset"); - currOffset_ = memSize_ + offset; + currOffset_ = memSize_ + static_cast(offset); } return PKG_SUCCESS; } diff --git a/services/package/pkg_manager/pkg_utils.cpp b/services/package/pkg_manager/pkg_utils.cpp index 554c4ed7..b4190497 100644 --- a/services/package/pkg_manager/pkg_utils.cpp +++ b/services/package/pkg_manager/pkg_utils.cpp @@ -39,8 +39,8 @@ using namespace updater::utils; std::string GetFilePath(const std::string &fileName) { - int32_t pos = fileName.find_last_of('/'); - if (pos < 0) { + size_t pos = fileName.find_last_of('/'); + if (pos == std::string::npos) { pos = fileName.find_last_of('\\'); } return fileName.substr(0, pos + 1); @@ -55,7 +55,7 @@ size_t GetFileSize(const std::string &fileName) PKG_CHECK(fp != nullptr, return 0, "Invalid file %s", fileName.c_str()); fseek(fp, 0, SEEK_END); - size_t size = ftell(fp); + size_t size = static_cast(ftell(fp)); fclose(fp); // return file size in bytes return size; diff --git a/services/package/pkg_package/pkg_gzipfile.h b/services/package/pkg_package/pkg_gzipfile.h index a06dd7e5..6250b0dd 100644 --- a/services/package/pkg_package/pkg_gzipfile.h +++ b/services/package/pkg_package/pkg_gzipfile.h @@ -25,7 +25,7 @@ struct __attribute__((packed)) GZipHeader { uint16_t magic = 0; uint8_t method = 0; uint8_t flags = 0; - uint32_t mtime = 0; + time_t mtime = 0; uint8_t xfl = 0; uint8_t osFile = 0; }; diff --git a/services/package/pkg_package/pkg_upgradefile.cpp b/services/package/pkg_package/pkg_upgradefile.cpp index 85d4e1e0..57a5bc43 100644 --- a/services/package/pkg_package/pkg_upgradefile.cpp +++ b/services/package/pkg_package/pkg_upgradefile.cpp @@ -120,7 +120,7 @@ int32_t UpgradePkgFile::SavePackage(size_t &signOffset) size_t offset = 0; // Package header information - WriteLE16(buffer.data(), GetPackageTlvType()); // Type is 1 for package header in TLV format + WriteLE16(buffer.data(), static_cast(GetPackageTlvType())); // Type is 1 for package header in TLV format WriteLE16(buffer.data() + sizeof(uint16_t), sizeof(UpgradePkgHeader)); offset += sizeof(PkgTlv); UpgradePkgHeader *header = reinterpret_cast(buffer.data() + offset); diff --git a/services/package/pkg_package/pkg_zipfile.cpp b/services/package/pkg_package/pkg_zipfile.cpp index 5ea2eb6b..9f572dc6 100644 --- a/services/package/pkg_package/pkg_zipfile.cpp +++ b/services/package/pkg_package/pkg_zipfile.cpp @@ -285,7 +285,7 @@ int32_t ZipFileEntry::EncodeCentralDirEntry(const PkgStreamPtr stream, size_t st if (fileInfo_.method == Z_DEFLATED) { centralDir->flags |= GPBDD_FLAG_MASK; } - centralDir->compressionMethod = fileInfo_.method; + centralDir->compressionMethod = static_cast(fileInfo_.method); centralDir->crc = crc32_; uint16_t date; uint16_t time; @@ -318,7 +318,7 @@ int32_t ZipFileEntry::EncodeLocalFileHeader(uint8_t *buffer, size_t bufferLen, b header->signature = LOCAL_HEADER_SIGNATURE; header->versionNeeded = 0; header->flags = 0; - header->compressionMethod = fileInfo_.method; + header->compressionMethod = static_cast(fileInfo_.method); uint16_t date; uint16_t time; ExtraTimeAndDate(fileInfo_.fileInfo.modifiedTime, date, time); @@ -405,7 +405,7 @@ int32_t ZipFileEntry::DecodeCentralDirEntry(PkgStreamPtr inStream, PkgBuffer &bu return PKG_SUCCESS; } uint8_t* extraData = buffer.buffer + nameSize + sizeof(CentralDirEntry); - int16_t headerId = ReadLE16(extraData); + uint16_t headerId = ReadLE16(extraData); if (headerId != 1) { // zip64 扩展 return PKG_SUCCESS; } diff --git a/services/script/script_instruction/script_basicinstruction.cpp b/services/script/script_instruction/script_basicinstruction.cpp index 905a80bb..b203f643 100644 --- a/services/script/script_instruction/script_basicinstruction.cpp +++ b/services/script/script_instruction/script_basicinstruction.cpp @@ -44,7 +44,7 @@ int32_t UScriptInstructionSleep::Execute(uscript::UScriptEnv &env, uscript::UScr int32_t seconds = 1; int32_t ret = context.GetParam(0, seconds); USCRIPT_CHECK(ret == USCRIPT_SUCCESS, return ret, "Failed to get param"); - sleep(seconds); + sleep(static_cast(seconds)); return USCRIPT_SUCCESS; } diff --git a/services/script/script_interpreter/script_scanner.cpp b/services/script/script_interpreter/script_scanner.cpp index 9119844f..cb74877d 100644 --- a/services/script/script_interpreter/script_scanner.cpp +++ b/services/script/script_interpreter/script_scanner.cpp @@ -22,7 +22,7 @@ int Scanner::LexerInput(char *buf, int maxSize) { size_t readLen = 0; PkgBuffer data = {reinterpret_cast(buf), static_cast(maxSize)}; - (void)pkgStream_->Read(data, currPos, maxSize, readLen); + (void)pkgStream_->Read(data, currPos, static_cast(maxSize), readLen); currPos += readLen; return readLen; } diff --git a/services/script/script_manager/script_managerImpl.cpp b/services/script/script_manager/script_managerImpl.cpp index e0889b3f..81cd5292 100644 --- a/services/script/script_manager/script_managerImpl.cpp +++ b/services/script/script_manager/script_managerImpl.cpp @@ -144,7 +144,7 @@ int32_t ScriptManagerImpl::ExecuteScript(int32_t priority) int32_t retCode = USCRIPT_SUCCESS; task.workSize = threadNumber; task.processor = [&](int iter) { - for (size_t i = iter; i < scriptFiles_[priority].size(); i += threadNumber) { + for (size_t i = static_cast(iter); i < scriptFiles_[priority].size(); i += threadNumber) { ret = ExtractAndExecuteScript(manager, scriptFiles_[priority][i]); if (ret != USCRIPT_SUCCESS) { USCRIPT_LOGE("Failed to execute script %s", scriptFiles_[priority][i].c_str()); diff --git a/services/ui/animation_label.cpp b/services/ui/animation_label.cpp index 5e4c0fc7..2b198cfe 100644 --- a/services/ui/animation_label.cpp +++ b/services/ui/animation_label.cpp @@ -214,7 +214,8 @@ void *AnimationLable::LoadPng(const std::string &imgFileName) char *pictureBufferTmp = nullptr; BRGA888Pixel *pictureBuffer = nullptr; char *backgroundBuffer = static_cast(GetRawBuffer()); - int pictureBufferSize = viewHeight_ * viewWidth_ * sizeof(BRGA888Pixel); + size_t pictureBufferSize = static_cast(viewHeight_) * static_cast(viewWidth_) + * sizeof(BRGA888Pixel); uint8_t *pictureRow = nullptr; FILE *fp = fopen(imgFileName.c_str(), "rb"); diff --git a/services/ui/drm_driver.cpp b/services/ui/drm_driver.cpp index 20119428..995bff5b 100644 --- a/services/ui/drm_driver.cpp +++ b/services/ui/drm_driver.cpp @@ -61,7 +61,8 @@ int DrmDriver::ModesetCreateFb(struct BufferObject *bo) /* map the dumb-buffer to userspace */ map.handle = create.handle; drmIoctl(fd_, DRM_IOCTL_MODE_MAP_DUMB, &map); - bo->vaddr = static_cast(mmap(0, create.size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_, map.offset)); + bo->vaddr = static_cast(mmap(0, create.size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_, + static_cast(map.offset))); const int newColor = 0xff000000; uint32_t i = 0; uint32_t color = newColor; diff --git a/services/ui/frame.cpp b/services/ui/frame.cpp index 27bc4145..2fbd5dbe 100644 --- a/services/ui/frame.cpp +++ b/services/ui/frame.cpp @@ -26,7 +26,7 @@ extern Frame *g_menuFrame; Frame::Frame(unsigned int w, unsigned int h, View::PixelFormat pixType, SurfaceDev *sfDev) { - this->CreateBuffer(w, h, pixType); + this->CreateBuffer(static_cast(w), static_cast(h), pixType); this->startX_ = 0; this->startY_ = 0; sfDev_ = sfDev; diff --git a/services/ui/progress_bar.cpp b/services/ui/progress_bar.cpp index d3df1185..bc0d794a 100644 --- a/services/ui/progress_bar.cpp +++ b/services/ui/progress_bar.cpp @@ -72,8 +72,9 @@ void ProgressBar::DrawProgress() pixBuf[a].a = progressColor_.a; } for (int i = 0; i < viewHeight_; i++) { - ret = memcpy_s(tmpBuf + i * viewWidth_ * sizeof(BRGA888Pixel), pixelLen * sizeof(BRGA888Pixel) + 1, - reinterpret_cast(pixBuf), pixelLen * sizeof(BRGA888Pixel)); + ret = memcpy_s(tmpBuf + i * viewWidth_ * sizeof(BRGA888Pixel), + static_cast(pixelLen) * sizeof(BRGA888Pixel) + 1, reinterpret_cast(pixBuf), + static_cast(pixelLen) * sizeof(BRGA888Pixel)); UPDATER_ERROR_CHECK(ret == 0, "memcpy_s error", break); } return; @@ -104,8 +105,9 @@ void ProgressBar::DrawBackground() pixBuf[a].a = normalColor_.a; } for (int i = 0; i < viewHeight_; i++) { - ret = memcpy_s(tmpBuf + i * viewWidth_ * sizeof(BRGA888Pixel), viewWidth_ * sizeof(BRGA888Pixel) + 1, - reinterpret_cast(pixBuf), viewWidth_ * sizeof(BRGA888Pixel)); + ret = memcpy_s(tmpBuf + i * viewWidth_ * sizeof(BRGA888Pixel), + static_cast(viewWidth_ * sizeof(BRGA888Pixel) + 1), + reinterpret_cast(pixBuf), static_cast(viewWidth_ * sizeof(BRGA888Pixel))); UPDATER_ERROR_CHECK(ret == 0, "memcpy_s error", break); } return; diff --git a/services/ui/text_label.cpp b/services/ui/text_label.cpp index d94a90a6..1abce1eb 100644 --- a/services/ui/text_label.cpp +++ b/services/ui/text_label.cpp @@ -237,7 +237,7 @@ void TextLabel::DrawText() int textSy = 0; switch (fontAligMethodUpright_) { case ALIGN_CENTER: - textSy = (viewHeight_ - fontHeight_) / MEDIAN_NUMBER; + textSy = (viewHeight_ - static_cast(fontHeight_)) / MEDIAN_NUMBER; break; case ALIGN_TO_TOP: textSy = 0; @@ -250,7 +250,7 @@ void TextLabel::DrawText() const int average = 2; switch (fontAligMethodLevel_) { case ALIGN_CENTER: - textSx = (viewWidth_ - (strlen(textBuf_) * fontWidth_)) / average; + textSx = (viewWidth_ - static_cast((strlen(textBuf_) * fontWidth_))) / average; UPDATER_CHECK_ONLY_RETURN(textSx >= minPosition, textSx = minPosition); break; case ALIGN_TO_LEFT: @@ -266,8 +266,8 @@ void TextLabel::DrawText() auto *srcP = reinterpret_cast(static_cast(fontBuf_) + ((ch - ' ') * fontWidth_)); auto *dstP = reinterpret_cast(static_cast(tmpBuf) + (textSy * viewWidth_ + textSx) * sizeof(BRGA888Pixel)); - for (unsigned int j = 0; j < fontHeight_; j++) { - for (unsigned int i = 0; i < fontWidth_; i++) { + for (int j = 0; j < static_cast(fontHeight_); j++) { + for (int i = 0; i < static_cast(fontWidth_); i++) { uint8_t a = srcP[i]; if (a > 0) { dstP[i].r = textColor_.r; @@ -279,7 +279,7 @@ void TextLabel::DrawText() srcP += MAX_FONT_BUFFER_SIZE_HW; dstP = dstP + viewWidth_; } - textSx += fontWidth_; + textSx += static_cast(fontWidth_); } } @@ -293,10 +293,11 @@ void TextLabel::DrawFocus() pixBuf[a].a = actionBgColor_.a; } void *viewBgBuf = GetBuffer(); - for (int i = 0; i < viewHeight_; i++) { - UPDATER_CHECK_ONLY_RETURN(!memcpy_s(static_cast(static_cast(viewBgBuf) + i * viewWidth_ * - sizeof(BRGA888Pixel)), viewWidth_ * sizeof(BRGA888Pixel) + 1, reinterpret_cast(pixBuf), - viewWidth_ * sizeof(BRGA888Pixel)), return); + for (size_t i = 0; i < static_cast(viewHeight_); i++) { + UPDATER_CHECK_ONLY_RETURN(!memcpy_s(static_cast(static_cast(viewBgBuf) + + i * static_cast(viewWidth_) * sizeof(BRGA888Pixel)), + static_cast(viewWidth_) * sizeof(BRGA888Pixel) + 1, + reinterpret_cast(pixBuf), viewWidth_ * sizeof(BRGA888Pixel)), return); } } diff --git a/services/ui/view.cpp b/services/ui/view.cpp index 3fe5e023..d35f8161 100644 --- a/services/ui/view.cpp +++ b/services/ui/view.cpp @@ -31,7 +31,7 @@ void *View::CreateBuffer(int w, int h, int pixelFormat) pixelSize = RGBA_PIXEL_SIZE; break; } - bufferSize_ = w * h * pixelSize; + bufferSize_ = static_cast(w * h * pixelSize); viewBuffer_ = static_cast(malloc(bufferSize_)); if (viewBuffer_ == nullptr) { LOG(ERROR) << "Allocate memory for view failed: " << errno; @@ -64,9 +64,10 @@ void View::SetBackgroundColor(BRGA888Pixel *color) pixelBuffer[w].b = color->b; pixelBuffer[w].a = color->a; } - for (int h = 0; h < viewHeight_; h++) { - UPDATER_CHECK_ONLY_RETURN(!memcpy_s(viewBuffer_ + h * viewWidth_ * sizeof(BRGA888Pixel), viewWidth_ * - sizeof(BRGA888Pixel) + 1, reinterpret_cast(pixelBuffer), viewWidth_ * sizeof(BRGA888Pixel)), + for (size_t h = 0; h < viewHeight_; h++) { + UPDATER_CHECK_ONLY_RETURN(!memcpy_s(viewBuffer_ + h * viewWidth_ * sizeof(BRGA888Pixel), + static_cast(viewWidth_) * sizeof(BRGA888Pixel) + 1, + reinterpret_cast(pixelBuffer), static_cast(viewWidth_) * sizeof(BRGA888Pixel)), return); } if (isVisiable_) { @@ -83,8 +84,8 @@ void View::DrawSubView(int x, int y, int w, int h, void *buf) for (int i = 0; i < minHeight; i++) { char *src = static_cast(buf) + i * w * sizeof(BRGA888Pixel); char *dst = shadowBuffer_ + (i + y) * viewWidth_ * sizeof(BRGA888Pixel) + x * sizeof(BRGA888Pixel); - UPDATER_CHECK_ONLY_RETURN(!memcpy_s(dst, minWidth * sizeof(BRGA888Pixel) + 1, src, minWidth * - sizeof(BRGA888Pixel)), return); + UPDATER_CHECK_ONLY_RETURN(!memcpy_s(dst, static_cast(minWidth) * sizeof(BRGA888Pixel) + 1, src, + static_cast(minWidth) * sizeof(BRGA888Pixel)), return); } } diff --git a/services/ui/view.h b/services/ui/view.h index 0f8fa7e0..edde1360 100644 --- a/services/ui/view.h +++ b/services/ui/view.h @@ -73,7 +73,7 @@ protected: char* viewBuffer_ = nullptr; char* shadowBuffer_ = nullptr; private: - int bufferSize_ = 0; + size_t bufferSize_ = 0; bool isVisiable_ = true; int viewId_ = 0; bool focusable_ = false; diff --git a/services/updater_binary/update_image_block.cpp b/services/updater_binary/update_image_block.cpp index cd042792..5d43bd1a 100644 --- a/services/updater_binary/update_image_block.cpp +++ b/services/updater_binary/update_image_block.cpp @@ -346,7 +346,7 @@ int32_t UScriptInstructionBlockCheck::Execute(uscript::UScriptEnv &env, uscript: ret = lseek64(fd, static_cast(it->first * H_BLOCK_SIZE), SEEK_SET); UPDATER_ERROR_CHECK(ret != -1, "Failed to seek", return ReturnAndPushParam(USCRIPT_ERROR_EXECUTE, context)); - size_t size = (it->second - it->first) * H_BLOCK_SIZE; + ssize_t size = static_cast(it->second - it->first) * H_BLOCK_SIZE; LOG(INFO) << "BlockSet::ReadDataFromBlock Read " << size << " from block"; UPDATER_ERROR_CHECK(utils::ReadFully(fd, block_buff.data() + pos, size), "Failed to read", return ReturnAndPushParam(USCRIPT_ERROR_EXECUTE, context)); diff --git a/services/updater_binary/update_partitions.cpp b/services/updater_binary/update_partitions.cpp index edd7fcab..96e0b07c 100644 --- a/services/updater_binary/update_partitions.cpp +++ b/services/updater_binary/update_partitions.cpp @@ -48,16 +48,25 @@ int UpdatePartitions::ParsePartitionInfo(const std::string &partitionInfo, Parti return 0; } cJSON* thisPartition = cJSON_GetArrayItem(partitions, i); - UPDATER_ERROR_CHECK(thisPartition != nullptr, "Error get thisPartion", free(myPartition); - myPartition = nullptr; break); + UPDATER_ERROR_CHECK(thisPartition != nullptr, "Error get thisPartion", free(myPartition); myPartition = nullptr; break); cJSON* item = cJSON_GetObjectItem(thisPartition, "start"); - UPDATER_ERROR_CHECK(item != nullptr, "Error get start", free(myPartition); myPartition = nullptr; break); - myPartition->start = item->valueint; + if (item == nullptr || item->valueint < 0) { + LOG(ERROR) << "start invalid!"; + free(myPartition); + myPartition = nullptr; + break; + } + myPartition->start = static_cast(item->valueint); item = cJSON_GetObjectItem(thisPartition, "length"); - UPDATER_ERROR_CHECK(item != nullptr, "Error get length", free(myPartition); myPartition = nullptr; break); - myPartition->length = item->valueint; + if (item == nullptr || item->valueint < 0) { + LOG(ERROR) << "Error get length"; + free(myPartition); + myPartition = nullptr; + break; + } + myPartition->length = static_cast(item->valueint); myPartition->partNum = 0; myPartition->devName = "mmcblk0px"; @@ -128,7 +137,7 @@ int32_t UpdatePartitions::Execute(uscript::UScriptEnv &env, uscript::UScriptCont return USCRIPT_ERROR_EXECUTE; } char partitionInfo[MAX_LOG_BUF_SIZE]; - int32_t partitionCount = fread(partitionInfo, 1, MAX_LOG_BUF_SIZE, fp); + size_t partitionCount = fread(partitionInfo, 1, MAX_LOG_BUF_SIZE, fp); fclose(fp); if (partitionCount <= LEAST_PARTITION_COUNT) { env.GetPkgManager()->ClosePkgStream(outStream); diff --git a/services/updater_main.cpp b/services/updater_main.cpp index 9b393a6d..be9abc15 100644 --- a/services/updater_main.cpp +++ b/services/updater_main.cpp @@ -245,7 +245,8 @@ static UpdaterStatus StartUpdater(PkgManager::PkgManagerPtr manager, const std:: } extractedArgs.push_back(nullptr); extractedArgs.insert(extractedArgs.begin(), argv[0]); - while ((rc = getopt_long(extractedArgs.size() - 1, extractedArgs.data(), "", OPTIONS, &optionIndex)) != -1) { + while ((rc = getopt_long(static_cast(extractedArgs.size()) - 1, + extractedArgs.data(), "", OPTIONS, &optionIndex)) != -1) { switch (rc) { case 0: { std::string option = OPTIONS[optionIndex].name; diff --git a/services/updater_utils.cpp b/services/updater_utils.cpp index dc928c74..ce91bdf9 100755 --- a/services/updater_utils.cpp +++ b/services/updater_utils.cpp @@ -97,8 +97,8 @@ bool CopyUpdaterLogs(const std::string &sLog, const std::string &dLog) char buf[MAX_LOG_BUF_SIZE]; size_t bytes; while ((bytes = fread(buf, 1, sizeof(buf), sFp)) != 0) { - int ret = fwrite(buf, 1, bytes, dFp); - if (ret < 0) { + size_t ret = fwrite(buf, 1, bytes, dFp); + if (ret == 0) { break; } } @@ -158,7 +158,7 @@ static bool ClearMisc() struct PartitionRecordInfo cleanPartition {}; for (size_t tmpOffset = 0; tmpOffset < PARTITION_UPDATER_RECORD_MSG_SIZE; tmpOffset += sizeof(PartitionRecordInfo)) { - (void)fseek(fp.get(), PARTITION_RECORD_START + tmpOffset, SEEK_SET); + (void)fseek(fp.get(), PARTITION_RECORD_START + static_cast(tmpOffset), SEEK_SET); UPDATER_FILE_CHECK(fwrite(&cleanPartition, sizeof(PartitionRecordInfo), 1, fp.get()) == 1, "ClearMisc write misc cleanPartition failed", return false); } diff --git a/test/unittest/applypatch_test/all_cmd_unittest.cpp b/test/unittest/applypatch_test/all_cmd_unittest.cpp index 489b5b26..69d857d4 100755 --- a/test/unittest/applypatch_test/all_cmd_unittest.cpp +++ b/test/unittest/applypatch_test/all_cmd_unittest.cpp @@ -77,7 +77,7 @@ bool AllCmdUnitTest::GetTransferContents(const std::string &transferFile, std::s bool AllCmdUnitTest::WriteTestBin(int fd, const uint8_t &data, size_t size) const { ssize_t written = 0; - size_t rest = size; + ssize_t rest = static_cast(size); size_t count = 4096; const uint8_t *p = &data; diff --git a/test/unittest/applypatch_test/applypatch_unittest.cpp b/test/unittest/applypatch_test/applypatch_unittest.cpp index 4f70a0ef..592b9ba7 100755 --- a/test/unittest/applypatch_test/applypatch_unittest.cpp +++ b/test/unittest/applypatch_test/applypatch_unittest.cpp @@ -95,7 +95,7 @@ HWTEST_F(ApplyPatchUnitTest, updater_RawWriter, TestSize.Level1) EXPECT_GE(fd, 0); uint8_t buffer[BUFFER_LEN + 1] = {0}; - size_t n = read(fd, buffer, BUFFER_LEN); + ssize_t n = read(fd, buffer, static_cast(BUFFER_LEN)); EXPECT_EQ(n, BUFFER_LEN); auto result = memcmp(buf, buffer, BUFFER_LEN); diff --git a/test/unittest/applypatch_test/imagepatch_unittest.cpp b/test/unittest/applypatch_test/imagepatch_unittest.cpp index f58c5fd5..620c1d4d 100755 --- a/test/unittest/applypatch_test/imagepatch_unittest.cpp +++ b/test/unittest/applypatch_test/imagepatch_unittest.cpp @@ -46,12 +46,12 @@ bool ImagePatchTest::ReadContentFromFile(const std::string& file, std::string &c close(fd); return false; } - content.reserve(st.st_size); + content.reserve(static_cast(st.st_size)); constexpr size_t bufferSize = 1024; char buffer[bufferSize]; ssize_t n; while ((n = read(fd, buffer, sizeof(buffer))) > 0) { - content.append(buffer, n); + content.append(buffer, static_cast(n)); } close(fd); return ((n == 0) ? true : false); diff --git a/test/unittest/diffpatch/diffpatch_unittest.cpp b/test/unittest/diffpatch/diffpatch_unittest.cpp index 9292e18f..47d0eb41 100755 --- a/test/unittest/diffpatch/diffpatch_unittest.cpp +++ b/test/unittest/diffpatch/diffpatch_unittest.cpp @@ -149,7 +149,7 @@ public: PATCH_CHECK(ret == 0, return -1, "Failed to apply block patch file"); std::ofstream stream(newName, std::ios::out | std::ios::binary); PATCH_CHECK(!stream.fail(), return -1, "Failed to open %s", newName.c_str()); - stream.write(reinterpret_cast(newData.data()), newData.size()); + stream.write(reinterpret_cast(newData.data()), static_cast(newData.size())); } else { std::unique_ptr writer = std::make_unique(newName); PATCH_CHECK(writer != nullptr, return -1, "Failed to create writer"); diff --git a/test/unittest/flashd_test/flash_host_unittest.cpp b/test/unittest/flashd_test/flash_host_unittest.cpp index e025ad56..b07e4553 100755 --- a/test/unittest/flashd_test/flash_host_unittest.cpp +++ b/test/unittest/flashd_test/flash_host_unittest.cpp @@ -63,7 +63,7 @@ public: return -1; } flashHost->CommandDispatch(command, - const_cast(reinterpret_cast(cmd.data())), cmd.size()); + const_cast(reinterpret_cast(cmd.data())), static_cast(cmd.size())); return 0; } @@ -85,33 +85,34 @@ public: return -1; } flashHost->CommandDispatch(command, - const_cast(reinterpret_cast(cmd.data())), cmd.size()); + const_cast(reinterpret_cast(cmd.data())), static_cast(cmd.size())); flashHost->OpenFile(); std::vector data(MAX_SIZE_IOBUF * 2); // 2 - flashHost->CommandDispatch(CMD_UPDATER_BEGIN, const_cast(data.data()), data.size()); + flashHost->CommandDispatch(CMD_UPDATER_BEGIN, const_cast(data.data()), + static_cast(data.size())); std::string cmdInfo = ""; flashHost->CommandDispatch(CMD_UPDATER_CHECK, - const_cast(reinterpret_cast(cmdInfo.data())), cmdInfo.size()); + const_cast(reinterpret_cast(cmdInfo.data())), static_cast(cmdInfo.size())); - flashHost->CommandDispatch(CMD_UPDATER_DATA, const_cast(data.data()), data.size()); + flashHost->CommandDispatch(CMD_UPDATER_DATA, const_cast(data.data()), static_cast(data.size())); vector info = {0, 1, 's', 'u', 'c', 'c', 'e', 's', 's'}; flashHost->CommandDispatch(CMD_UPDATER_FINISH, - const_cast(reinterpret_cast(info.data())), info.size()); + const_cast(reinterpret_cast(info.data())), static_cast(info.size())); uint32_t percentage = 30; // 30 progress cmdInfo.resize(sizeof(percentage)); (void)memcpy_s(cmdInfo.data(), cmdInfo.size(), &percentage, sizeof(percentage)); flashHost->CommandDispatch(CMD_UPDATER_PROGRESS, - const_cast(reinterpret_cast(cmdInfo.data())), cmdInfo.size()); + const_cast(reinterpret_cast(cmdInfo.data())), static_cast(cmdInfo.size())); percentage = static_cast(progress); cmdInfo.resize(sizeof(percentage)); (void)memcpy_s(cmdInfo.data(), cmdInfo.size(), &percentage, sizeof(percentage)); flashHost->CommandDispatch(CMD_UPDATER_PROGRESS, - const_cast(reinterpret_cast(cmdInfo.data())), cmdInfo.size()); + const_cast(reinterpret_cast(cmdInfo.data())), static_cast(cmdInfo.size())); return 0; } }; diff --git a/test/unittest/flashd_test/flash_service_unittest.cpp b/test/unittest/flashd_test/flash_service_unittest.cpp index 32b63600..8190b2ab 100755 --- a/test/unittest/flashd_test/flash_service_unittest.cpp +++ b/test/unittest/flashd_test/flash_service_unittest.cpp @@ -81,7 +81,7 @@ public: return 1; } flash->DoUpdate(TEST_UPDATER_PACKAGE_PATH); - flash->PostProgress(UPDATEMOD_UPDATE, 1024 * 1024 * 4, nullptr); // 1024 * 1024 * 4 4M + flash->PostProgress(UPDATEMOD_UPDATE, static_cast(1024 * 1024 * 4), nullptr); // 1024 * 1024 * 4 4M return 0; } @@ -188,7 +188,7 @@ public: EXPECT_EQ(0, ret); ret = memcpy_s(buffer.data() + sizeof(realSize), buffer.size(), bufString.c_str(), bufString.size()); EXPECT_EQ(0, ret); - hdcDamon->CommandDispatch(CMD_UPDATER_CHECK, buffer.data(), buffer.size()); + hdcDamon->CommandDispatch(CMD_UPDATER_CHECK, buffer.data(), static_cast(buffer.size())); // begin hdcDamon->CommandDispatch(CMD_UPDATER_BEGIN, NULL, 0); @@ -244,7 +244,7 @@ public: EXPECT_EQ(0, ret); ret = memcpy_s(buffer.data() + sizeof(realSize), buffer.size(), bufString.c_str(), bufString.size()); EXPECT_EQ(0, ret); - hdcDamon->CommandDispatch(CMD_UPDATER_CHECK, buffer.data(), buffer.size()); + hdcDamon->CommandDispatch(CMD_UPDATER_CHECK, buffer.data(), static_cast(buffer.size())); return 0; } @@ -285,7 +285,7 @@ public: EXPECT_EQ(0, ret); ret = memcpy_s(buffer.data() + sizeof(realSize), buffer.size(), bufString.c_str(), bufString.size()); EXPECT_EQ(0, ret); - hdcDamon->CommandDispatch(CMD_UPDATER_CHECK, buffer.data(), buffer.size()); + hdcDamon->CommandDispatch(CMD_UPDATER_CHECK, buffer.data(), static_cast(buffer.size())); // begin hdcDamon->CommandDispatch(CMD_UPDATER_BEGIN, NULL, 0); @@ -297,10 +297,12 @@ public: payloadHead.compressSize = transferConfig.fileSize / 10; // 10 time payloadHead.index = 0; std::string bufData = SerialStruct::SerializeToString(payloadHead); - hdcDamon->CommandDispatch(CMD_UPDATER_DATA, reinterpret_cast(bufData.data()), bufData.size()); + hdcDamon->CommandDispatch(CMD_UPDATER_DATA, reinterpret_cast(bufData.data()), + static_cast(bufData.size())); } std::string bufData = SerialStruct::SerializeToString(payloadHead); - hdcDamon->CommandDispatch(CMD_UPDATER_DATA, reinterpret_cast(bufData.data()), bufData.size()); + hdcDamon->CommandDispatch(CMD_UPDATER_DATA, reinterpret_cast(bufData.data()), + static_cast(bufData.size())); // end hdcDamon->DoTransferFinish(); return 0; @@ -356,9 +358,9 @@ public: // check std::string bufString = "format -f "; bufString += TEST_PARTITION_NAME + " -t ext4"; - hdcDamon->CommandDispatch(CMD_UPDATER_FORMAT, reinterpret_cast(bufString.data()), bufString.size()); - return 0; + return hdcDamon->CommandDispatch(CMD_UPDATER_FORMAT, reinterpret_cast(bufString.data()), + static_cast(bufString.size())); } }; diff --git a/test/unittest/package/package_unittest.cpp b/test/unittest/package/package_unittest.cpp index 5031c3e0..3dc32f34 100755 --- a/test/unittest/package/package_unittest.cpp +++ b/test/unittest/package/package_unittest.cpp @@ -48,7 +48,7 @@ public: pkgInfo.time = strdup("21:23:49"); pkgInfo.productUpdateId = strdup("555.555.100.555"); pkgInfo.entryCount = testFileNames_.size(); - pkgInfo.digestMethod = type; + pkgInfo.digestMethod = static_cast(type); pkgInfo.signMethod = PKG_SIGN_METHOD_RSA; pkgInfo.pkgType = PKG_PACK_TYPE_UPGRADE; pkgInfo.updateFileVersion = updateFileVersion; diff --git a/test/unittest/package/pkg_algo_unittest.cpp b/test/unittest/package/pkg_algo_unittest.cpp index 43836721..1e7778b1 100755 --- a/test/unittest/package/pkg_algo_unittest.cpp +++ b/test/unittest/package/pkg_algo_unittest.cpp @@ -103,8 +103,8 @@ public: { constexpr int8_t invalidType = 100; constexpr size_t digestLen = 32; - constexpr int16_t magicNumber = 256; - int ret = DigestAlgorithm::GetDigestLen(invalidType); + constexpr size_t magicNumber = 256; + size_t ret = DigestAlgorithm::GetDigestLen(invalidType); EXPECT_EQ(0, ret); ret = DigestAlgorithm::GetSignatureLen(invalidType); EXPECT_EQ(magicNumber, ret); @@ -169,7 +169,7 @@ public: UpgradePkgInfoExt pkgInfo; pkgInfo.entryCount = testFileNames_.size(); pkgInfo.digestMethod = PKG_DIGEST_TYPE_SHA256; - pkgInfo.signMethod = signMethod; + pkgInfo.signMethod = static_cast(signMethod); pkgInfo.pkgType = PKG_PACK_TYPE_ZIP; pkgInfo.updateFileVersion = updateFileVersion; std::string filePath; diff --git a/test/unittest/package/pkg_manager_unittest.cpp b/test/unittest/package/pkg_manager_unittest.cpp index dcbf120d..395c8b9b 100755 --- a/test/unittest/package/pkg_manager_unittest.cpp +++ b/test/unittest/package/pkg_manager_unittest.cpp @@ -219,7 +219,7 @@ public: offset = 0 - offset; ret = memStream->Seek(offset, SEEK_END); EXPECT_EQ(ret, PKG_SUCCESS); - ret = memStream->Flush(offset); + ret = memStream->Flush(static_cast(offset)); EXPECT_EQ(0, ret); ret = memStream->GetBuffer(data); EXPECT_EQ(0, ret); @@ -331,9 +331,9 @@ public: EXPECT_EQ(ret, PKG_INVALID_STREAM); ret = ((ProcessorStream*)outStream)->Seek(offset, SEEK_END); EXPECT_EQ(ret, PKG_SUCCESS); - ret = ((ProcessorStream*)outStream)->Flush(offset); + ret = ((ProcessorStream*)outStream)->Flush(static_cast(offset)); EXPECT_EQ(0, ret); - ret = ((ProcessorStream*)outStream)->GetFileLength(); + ret = static_cast(((ProcessorStream*)outStream)->GetFileLength()); EXPECT_EQ(0, ret); pkgManager_->ClosePkgStream(outStream); return ret; diff --git a/test/unittest/package/pkg_package_unittest.cpp b/test/unittest/package/pkg_package_unittest.cpp index 56578540..b7a91051 100755 --- a/test/unittest/package/pkg_package_unittest.cpp +++ b/test/unittest/package/pkg_package_unittest.cpp @@ -136,7 +136,7 @@ public: size_t offsetWord = 4; size_t offset4Words = 16; size_t offset3Words = 12; - int32_t buffLen = MAX_FILE_NAME + sizeof(LocalFileHeader) + sizeof(DataDescriptor) + + size_t buffLen = MAX_FILE_NAME + sizeof(LocalFileHeader) + sizeof(DataDescriptor) + sizeof(CentralDirEntry) + offsetWord + offset4Words; std::vector buff(buffLen); CentralDirEntry* centralDir = (CentralDirEntry *)buff.data(); diff --git a/test/unittest/package/pkg_test.h b/test/unittest/package/pkg_test.h index 315cb420..c28e63b6 100755 --- a/test/unittest/package/pkg_test.h +++ b/test/unittest/package/pkg_test.h @@ -158,7 +158,7 @@ protected: PkgInfo pkgInfo; pkgInfo.signMethod = PKG_SIGN_METHOD_RSA; - pkgInfo.digestMethod = digestMethod; + pkgInfo.digestMethod = static_cast(digestMethod); pkgInfo.pkgType = PKG_PACK_TYPE_ZIP; int32_t ret = pkgManager->CreatePackage(packageName, GetTestPrivateKeyName(digestMethod), &pkgInfo, files); EXPECT_EQ(ret, 0); diff --git a/test/unittest/script/threadpool_unittest.cpp b/test/unittest/script/threadpool_unittest.cpp index 7b9c3866..2e27ea77 100755 --- a/test/unittest/script/threadpool_unittest.cpp +++ b/test/unittest/script/threadpool_unittest.cpp @@ -55,7 +55,7 @@ public: size_t taskNumberRound = 20; task.workSize = taskNumber; task.processor = [&](int iter) { - for (size_t i = iter; i < taskNumberRound; i += taskNumber) { + for (size_t i = static_cast(iter); i < taskNumberRound; i += taskNumber) { printf("Run thread %zu %d \n", i, gettid()); } }; diff --git a/test/unittest/updater_binary/updater_binary_unittest.cpp b/test/unittest/updater_binary/updater_binary_unittest.cpp index d6a48a4d..3d9a2e04 100755 --- a/test/unittest/updater_binary/updater_binary_unittest.cpp +++ b/test/unittest/updater_binary/updater_binary_unittest.cpp @@ -121,8 +121,8 @@ protected: pkgInfo.productUpdateId = strdup("555.555.100.555"); int fileNameIndex = 3; uint8_t componentType = 22; - pkgInfo.entryCount = testFileNames_.size() + fileNameIndex; - pkgInfo.updateFileVersion = updateFileVersion; + pkgInfo.entryCount = testFileNames_.size() + static_cast(fileNameIndex); + pkgInfo.updateFileVersion = static_cast(updateFileVersion); pkgInfo.digestMethod = PKG_DIGEST_TYPE_SHA256; pkgInfo.signMethod = PKG_SIGN_METHOD_RSA; pkgInfo.pkgType = PKG_PACK_TYPE_UPGRADE; diff --git a/test/unittest/utils/utils_unittest.cpp b/test/unittest/utils/utils_unittest.cpp index eb40b025..7ac8702b 100755 --- a/test/unittest/utils/utils_unittest.cpp +++ b/test/unittest/utils/utils_unittest.cpp @@ -19,7 +19,7 @@ #include #include "utils.h" -using namespace updater; +using namespace updater; using namespace testing::ext; using namespace std; @@ -66,10 +66,10 @@ HWTEST_F(UtilsUnitTest, updater_utils_test_004, TestSize.Level0) HWTEST_F(UtilsUnitTest, updater_utils_test_005, TestSize.Level0) { string input = ""; - int output = utils::String2Int(input, 10); + size_t output = utils::String2Int(input, 10); EXPECT_EQ(output, 0); input = "0x01"; - output = utils::String2Int(input, 10); + output = utils::String2Int(input, 10); EXPECT_EQ(output, 1); } diff --git a/utils/include/utils.h b/utils/include/utils.h index 62366084..a8530006 100644 --- a/utils/include/utils.h +++ b/utils/include/utils.h @@ -51,7 +51,7 @@ std::string ConvertSha256Hex(const uint8_t* shaDigest, size_t length); void DoReboot(const std::string& rebootTarget, const std::string& extData = ""); std::string GetCertName(); bool WriteFully(int fd, const void *data, size_t size); -bool ReadFully(int fd, void* data, size_t size); +bool ReadFully(int fd, void* data, ssize_t size); bool ReadFileToString(int fd, std::string &content); bool WriteStringToFile(int fd, const std::string& content); std::string GetLocalBoardId(); diff --git a/utils/utils.cpp b/utils/utils.cpp index 3da6a9a1..5e10f7e8 100644 --- a/utils/utils.cpp +++ b/utils/utils.cpp @@ -222,12 +222,12 @@ std::string GetCertName() bool WriteFully(int fd, const void *data, size_t size) { ssize_t written = 0; - size_t rest = size; + ssize_t rest = size; auto p = reinterpret_cast(data); while (rest > 0) { do { - written = write(fd, p, rest); + written = write(fd, p, static_cast(rest)); } while (written < 0 && errno == EINTR); if (written < 0) { @@ -239,10 +239,10 @@ bool WriteFully(int fd, const void *data, size_t size) return true; } -bool ReadFully(int fd, void *data, size_t size) +bool ReadFully(int fd, void *data, ssize_t size) { auto p = reinterpret_cast(data); - size_t remaining = size; + ssize_t remaining = size; while (remaining > 0) { ssize_t sread = read(fd, p, remaining); UPDATER_ERROR_CHECK (sread > 0, "Utils::ReadFully run error", return false); @@ -256,10 +256,10 @@ bool ReadFileToString(int fd, std::string &content) { struct stat sb {}; if (fstat(fd, &sb) != -1 && sb.st_size > 0) { - content.resize(sb.st_size); + content.resize(static_cast(sb.st_size)); } ssize_t n; - size_t remaining = sb.st_size; + ssize_t remaining = sb.st_size; auto p = reinterpret_cast(content.data()); while (remaining > 0) { n = read(fd, p, remaining); @@ -273,7 +273,7 @@ bool ReadFileToString(int fd, std::string &content) bool WriteStringToFile(int fd, const std::string& content) { const char *p = content.data(); - size_t remaining = content.size(); + ssize_t remaining = static_cast(content.size()); while (remaining > 0) { ssize_t n = write(fd, p, remaining); UPDATER_CHECK_ONLY_RETURN (n != -1, return false); -- Gitee