Skip to content

Commit 279a7b3

Browse files
authored
Merge pull request #221 from liulanzheng/main
fix all sign-compare warnings
2 parents e0a5712 + a8fe26d commit 279a7b3

File tree

14 files changed

+32
-31
lines changed

14 files changed

+32
-31
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ set(EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/build/output")
1717

1818
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMake")
1919

20-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpic")
21-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpic")
20+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpic -Wall -Werror=sign-compare")
21+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpic -Wall -Werror=sign-compare")
2222

2323
if (${ARCH} STREQUAL aarch64)
2424
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char")

src/bk_download.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ std::string sha256sum(const char *fn) {
5555
SHA256_Init(&ctx);
5656
__attribute__((aligned(ALIGNMENT))) char buffer[65536];
5757
unsigned char sha[32];
58-
int recv = 0;
58+
ssize_t recv = 0;
5959
for (off_t offset = 0; offset < stat.st_size; offset += BUFFERSIZE) {
6060
recv = pread(fd, &buffer, BUFFERSIZE, offset);
6161
if (recv < 0) {

src/overlaybd/cache/download_cache/download_cache.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,13 @@ ssize_t DownloadCacheFile::preadv(const struct iovec *iov, int iovcnt, off_t off
226226
read = m_file->preadv(buffer.iovec(), buffer.iovcnt(), r_offset);
227227
}
228228

229-
if (read != r_count) {
229+
if (read != (ssize_t)r_count) {
230230
LOG_ERRNO_RETURN(0, -1, "src file read failed, read: `, expect: `, size: `, offset: `",
231231
read, r_count, m_size, r_offset);
232232
}
233233

234234
auto write = m_local_file->pwritev(buffer.iovec(), buffer.iovcnt(), r_offset);
235-
if (write != r_count) {
235+
if (write != (ssize_t)r_count) {
236236
LOG_ERRNO_RETURN(0, -1, "local file write failed, write: `, expect: `, size: `, offset: `",
237237
write, r_count, m_size, r_offset);
238238
}

src/overlaybd/cache/ocf_cache/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ file(GLOB_RECURSE src_ocf ocf/src/*.c)
1212
add_library(ocf_lib STATIC ${src_ocf})
1313
target_include_directories(ocf_lib PUBLIC include/ ease_bindings/env/)
1414
target_link_libraries(ocf_lib ocf_env_lib z)
15+
target_compile_options(ocf_lib PUBLIC -Wno-sign-compare)
1516

1617
# ocf_cache_lib
1718
file(GLOB src_ocf_cache ocf_cache.cpp ocf_namespace.cpp ease_bindings/*.cpp)

src/overlaybd/cache/ocf_cache/ocf_cache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ int OcfCachedFile::fadvise(off_t offset, off_t len, int advice) {
191191
if (advice == POSIX_FADV_WILLNEED) {
192192
void *buf = m_fs->get_io_alloc()->alloc(len);
193193
DEFER(m_fs->get_io_alloc()->dealloc(buf));
194-
int ret = pread(buf, len, offset);
194+
auto ret = pread(buf, len, offset);
195195
if (ret < 0) {
196196
LOG_ERROR_RETURN(0, -1, "prefetch read failed");
197197
}

src/overlaybd/extfs/extfs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ int do_ext2fs_access(ext2_filsys fs, const char *path, int mode) {
813813
mode_t perms = inode.i_mode & 0777;
814814
if ((mode & W_OK) && (inode.i_flags & EXT2_IMMUTABLE_FL))
815815
return -EACCES;
816-
if ((mode & perms) == mode)
816+
if ((mode & perms) == (mode_t)mode)
817817
return 0;
818818
return -EACCES;
819819
}
@@ -996,7 +996,7 @@ int do_ext2fs_fiemap(ext2_filsys fs, ext2_ino_t ino, struct photon::fs::fiemap*
996996
if (ret) return parse_extfs_error(fs, ino, ret);
997997
map->fm_mapped_extents = blocks.size();
998998
photon::fs::fiemap_extent *ext_buf = &map->fm_extents[0];
999-
for (int i = 0; i < blocks.size(); i++) {
999+
for (uint32_t i = 0; i < blocks.size(); i++) {
10001000
LOG_DEBUG("find block ` `", blocks[i].first * fs->blocksize, blocks[i].second * fs->blocksize);
10011001
ext_buf[i].fe_physical = blocks[i].first * fs->blocksize;
10021002
ext_buf[i].fe_length = blocks[i].second * fs->blocksize;

src/overlaybd/lsmt/file.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ struct HeaderTrailer {
180180

181181
class LSMTReadOnlyFile;
182182
static LSMTReadOnlyFile *open_file_ro(IFile *file, bool ownership, bool reserve_tag);
183-
static HeaderTrailer *verify_ht(IFile *file, char *buf, bool is_trailer = false, size_t st_size = -1);
183+
static HeaderTrailer *verify_ht(IFile *file, char *buf, bool is_trailer = false, ssize_t st_size = -1);
184184

185185
static const uint32_t ALIGNMENT = 512; // same as trim block size.
186186
static const uint32_t ALIGNMENT4K = 4096;
@@ -1111,7 +1111,7 @@ class LSMTWarpFile : public LSMTFile {
11111111
LOG_DEBUG("write index to dest_file `, offset: `, size: `*`", dest_file, index_offset,
11121112
index_size, sizeof(SegmentMapping));
11131113
auto nwrite = dest_file->write(&compact_index[0], index_size * sizeof(SegmentMapping));
1114-
if (nwrite != (ssize_t)index_size * sizeof(SegmentMapping)) {
1114+
if (nwrite != (ssize_t)(index_size * sizeof(SegmentMapping))) {
11151115
LOG_ERRNO_RETURN(0, -1, "write index failed");
11161116
}
11171117
nindex = index_size;
@@ -1145,7 +1145,7 @@ class LSMTWarpFile : public LSMTFile {
11451145
}
11461146
};
11471147

1148-
static HeaderTrailer *verify_ht(IFile *file, char *buf, bool is_trailer, size_t st_size) {
1148+
static HeaderTrailer *verify_ht(IFile *file, char *buf, bool is_trailer, ssize_t st_size) {
11491149
if (file == nullptr) {
11501150
LOG_ERRNO_RETURN(0, nullptr, "invalid file ptr (null).");
11511151
}

src/overlaybd/registryfs/registryfs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ class RegistryFileImpl : public photon::fs::VirtualReadOnlyFile {
403403
again:
404404
photon::net::IOVWriter container(iov, iovcnt);
405405
auto count = container.sum();
406-
if ((ssize_t)count + offset > filesize)
406+
if (count + offset > filesize)
407407
count = filesize - offset;
408408
LOG_DEBUG("pulling blob from docker registry: ", VALUE(m_url), VALUE(offset), VALUE(count));
409409

src/overlaybd/registryfs/registryfs_v2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ class RegistryFileImpl_v2 : public photon::fs::VirtualReadOnlyFile {
356356
again:
357357
iovector_view view((struct iovec*)iov, iovcnt);
358358
auto count = view.sum();
359-
if ((ssize_t)count + offset > filesize)
359+
if (count + offset > filesize)
360360
count = filesize - offset;
361361
LOG_DEBUG("pulling blob from registry: ", VALUE(m_url), VALUE(offset), VALUE(count));
362362

src/overlaybd/tar/libtar.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ int UnTar::extract_regfile_meta_only(const char *filename) {
207207
fout->fallocate(0, 0, size);
208208
struct photon::fs::fiemap_t<8192> fie(0, size);
209209
fout->fiemap(&fie);
210-
for (int i = 0; i < fie.fm_mapped_extents; i++) {
210+
for (uint32_t i = 0; i < fie.fm_mapped_extents; i++) {
211211
LSMT::RemoteMapping lba;
212212
lba.offset = fie.fm_extents[i].fe_physical;
213213
lba.count = fie.fm_extents[i].fe_length;
@@ -252,11 +252,11 @@ int UnTar::extract_regfile(const char *filename) {
252252
rsz = left & fs_blockmask;
253253
else
254254
rsz = (left & ~T_BLOCKMASK) ? (left & T_BLOCKMASK) + T_BLOCKSIZE : (left & T_BLOCKMASK);
255-
if (file->read(buf, rsz) != rsz) {
255+
if (file->read(buf, rsz) != (ssize_t)rsz) {
256256
LOG_ERRNO_RETURN(0, -1, "failed to read block");
257257
}
258258
size_t wsz = (left < rsz) ? left : rsz;
259-
if (fout->pwrite(buf, wsz, pos) != wsz) {
259+
if (fout->pwrite(buf, wsz, pos) != (ssize_t)wsz) {
260260
LOG_ERRNO_RETURN(0, -1, "failed to write file");
261261
}
262262
pos += wsz;

0 commit comments

Comments
 (0)