From e98d67d2ec51bb40dee8914b91ab7d3ce2563bbf Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 19 Dec 2023 19:06:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: unknown --- frameworks/native/backup_ext/src/tar_file.cpp | 32 +++++++++---------- .../native/backup_ext/src/untar_file.cpp | 4 +-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/frameworks/native/backup_ext/src/tar_file.cpp b/frameworks/native/backup_ext/src/tar_file.cpp index aa1ebee0d..1e10765db 100644 --- a/frameworks/native/backup_ext/src/tar_file.cpp +++ b/frameworks/native/backup_ext/src/tar_file.cpp @@ -210,24 +210,24 @@ bool TarFile::WriteFileContent(const string &fileName, off_t size) while (remain > 0) { size_t read = ioBuffer_.size(); if (size < ioBuffer_.size()) { - read = size; + read = (size_t)size; } else { if (read > remain) { - read = remain; + read = (size_t)remain; } } // read buffer from src file - if (ReadAll(fd, ioBuffer_, size) != read) { + if (ReadAll(fd, ioBuffer_, size) != (int)read) { HILOGE("Failed to read all"); break; } // write buffer to tar file - if (SplitWriteAll(ioBuffer_, read, isFilled) != read) { + if (SplitWriteAll(ioBuffer_, read, isFilled) != (int)read) { HILOGE("Failed to split write all"); break; } - remain -= read; + remain -= (off_t)read; } close(fd); @@ -244,8 +244,8 @@ bool TarFile::WriteFileContent(const string &fileName, off_t size) int TarFile::SplitWriteAll(const vector &ioBuffer, int read, bool &isFilled) { size_t len = ioBuffer.size(); - if (len > read) { - len = read; + if (len > (size_t)read) { + len = (size_t)read; } size_t count = 0; while (count < len) { @@ -325,11 +325,11 @@ void TarFile::SetCheckSum(TarHeader &hdr) vector buffer {}; buffer.resize(sizeof(hdr)); buffer.assign(reinterpret_cast(&hdr), reinterpret_cast(&hdr) + sizeof(hdr)); - for (int index = 0; index < BLOCK_SIZE; index++) { - if (index < CHKSUM_BASE || index > CHKSUM_BASE + CHKSUM_LEN - 1) { - sum += (buffer[index] & 0xFF); + for (int index = 0; (uint32_t)index < BLOCK_SIZE; index++) { + if ((uint32_t)index < CHKSUM_BASE || (uint32_t)index > CHKSUM_BASE + CHKSUM_LEN - 1) { + sum += (int)(buffer[index] & 0xFF); } else { - sum += BLANK_SPACE; + sum += (int)BLANK_SPACE; } } memcpy_s(hdr.chksum, sizeof(hdr.chksum), I2Ocs(sizeof(hdr.chksum), sum).c_str(), sizeof(hdr.chksum) - 1); @@ -340,12 +340,12 @@ void TarFile::FillOwnerName(TarHeader &hdr, const struct stat &st) struct passwd *pw = getpwuid(st.st_uid); if (pw != nullptr) { int ret = snprintf_s(hdr.uname, sizeof(hdr.uname), sizeof(hdr.uname) - 1, "%s", pw->pw_name); - if (ret < 0 || ret >= sizeof(hdr.uname)) { + if (ret < 0 || ret >= (int)sizeof(hdr.uname)) { HILOGE("Fill pw_name failed, err = %{public}d", errno); } } else { int ret = snprintf_s(hdr.uname, sizeof(hdr.uname), sizeof(hdr.uname) - 1, "%d", st.st_uid); - if (ret < 0 || ret >= sizeof(hdr.uname)) { + if (ret < 0 || ret >= (int)sizeof(hdr.uname)) { HILOGE("Fill uid failed, err = %{public}d", errno); } } @@ -353,12 +353,12 @@ void TarFile::FillOwnerName(TarHeader &hdr, const struct stat &st) struct group *gr = getgrgid(st.st_gid); if (gr != nullptr) { int ret = snprintf_s(hdr.gname, sizeof(hdr.gname), sizeof(hdr.gname) - 1, "%s", gr->gr_name); - if (ret < 0 || ret >= sizeof(hdr.gname)) { + if (ret < 0 || ret >= (int)sizeof(hdr.gname)) { HILOGE("Fill gr_name failed, err = %{public}d", errno); } } else { int ret = snprintf_s(hdr.gname, sizeof(hdr.gname), sizeof(hdr.gname) - 1, "%d", st.st_gid); - if (ret < 0 || ret >= sizeof(hdr.gname)) { + if (ret < 0 || ret >= (int)sizeof(hdr.gname)) { HILOGE("Fill gid failed, err = %{public}d", errno); } } @@ -368,7 +368,7 @@ int TarFile::ReadAll(int fd, vector &ioBuffer, off_t size) { size_t count = 0; size_t len = ioBuffer.size(); - if (len > size) { + if (len > (size_t)size) { len = size; } while (count < len) { diff --git a/frameworks/native/backup_ext/src/untar_file.cpp b/frameworks/native/backup_ext/src/untar_file.cpp index 6e8ff73f2..ab51adb64 100644 --- a/frameworks/native/backup_ext/src/untar_file.cpp +++ b/frameworks/native/backup_ext/src/untar_file.cpp @@ -130,7 +130,7 @@ int UntarFile::ParseTarFile(const string &rootPath) TarHeader *header = reinterpret_cast(buff); if (!IsValidTarBlock(*header)) { // when split unpack, ftell size is over than file really size [0,READ_BUFF_SIZE] - if (ftello(tarFilePtr_) > (tarFileSize_ + READ_BUFF_SIZE) || !IsEmptyBlock(buff)) { + if (ftello(tarFilePtr_) > (tarFileSize_ + (off_t)READ_BUFF_SIZE) || !IsEmptyBlock(buff)) { HILOGE("Invalid tar file format"); ret = ERR_FORMAT; } @@ -186,7 +186,7 @@ void UntarFile::ParseRegularFile(FileStatInfo &info, char typeFlag, bool &isSkip string destStr(""); destStr.resize(READ_BUFF_SIZE); off_t remainSize = tarFileSize_; - size_t readBuffSize = READ_BUFF_SIZE; + size_t readBuffSize = (size_t)READ_BUFF_SIZE; while (remainSize > 0) { if (remainSize < READ_BUFF_SIZE) { readBuffSize = remainSize; -- Gitee