fix sign compare warnings (#5651)

Summary:
Fix -Wsign-compare warnings for gcc9.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5651

Test Plan: Tested with ubuntu19.10+gcc9

Differential Revision: D16567428

fbshipit-source-id: 730b2704d42ba0c4e4ea946a3199bbb34be4c25c
main
Yi Wu 5 years ago committed by Facebook Github Bot
parent 399f477818
commit 849a8c0ae0
  1. 14
      env/io_posix.cc
  2. 3
      port/port_posix.cc

14
env/io_posix.cc vendored

@ -803,8 +803,8 @@ Status PosixMmapFile::InvalidateCache(size_t offset, size_t length) {
#ifdef ROCKSDB_FALLOCATE_PRESENT #ifdef ROCKSDB_FALLOCATE_PRESENT
Status PosixMmapFile::Allocate(uint64_t offset, uint64_t len) { Status PosixMmapFile::Allocate(uint64_t offset, uint64_t len) {
assert(offset <= std::numeric_limits<off_t>::max()); assert(offset <= static_cast<uint64_t>(std::numeric_limits<off_t>::max()));
assert(len <= std::numeric_limits<off_t>::max()); assert(len <= static_cast<uint64_t>(std::numeric_limits<off_t>::max()));
TEST_KILL_RANDOM("PosixMmapFile::Allocate:0", rocksdb_kill_odds); TEST_KILL_RANDOM("PosixMmapFile::Allocate:0", rocksdb_kill_odds);
int alloc_status = 0; int alloc_status = 0;
if (allow_fallocate_) { if (allow_fallocate_) {
@ -873,7 +873,7 @@ Status PosixWritableFile::PositionedAppend(const Slice& data, uint64_t offset) {
assert(IsSectorAligned(data.size(), GetRequiredBufferAlignment())); assert(IsSectorAligned(data.size(), GetRequiredBufferAlignment()));
assert(IsSectorAligned(data.data(), GetRequiredBufferAlignment())); assert(IsSectorAligned(data.data(), GetRequiredBufferAlignment()));
} }
assert(offset <= std::numeric_limits<off_t>::max()); assert(offset <= static_cast<uint64_t>(std::numeric_limits<off_t>::max()));
const char* src = data.data(); const char* src = data.data();
size_t nbytes = data.size(); size_t nbytes = data.size();
if (!PosixPositionedWrite(fd_, src, nbytes, static_cast<off_t>(offset))) { if (!PosixPositionedWrite(fd_, src, nbytes, static_cast<off_t>(offset))) {
@ -1009,8 +1009,8 @@ Status PosixWritableFile::InvalidateCache(size_t offset, size_t length) {
#ifdef ROCKSDB_FALLOCATE_PRESENT #ifdef ROCKSDB_FALLOCATE_PRESENT
Status PosixWritableFile::Allocate(uint64_t offset, uint64_t len) { Status PosixWritableFile::Allocate(uint64_t offset, uint64_t len) {
assert(offset <= std::numeric_limits<off_t>::max()); assert(offset <= static_cast<uint64_t>(std::numeric_limits<off_t>::max()));
assert(len <= std::numeric_limits<off_t>::max()); assert(len <= static_cast<uint64_t>(std::numeric_limits<off_t>::max()));
TEST_KILL_RANDOM("PosixWritableFile::Allocate:0", rocksdb_kill_odds); TEST_KILL_RANDOM("PosixWritableFile::Allocate:0", rocksdb_kill_odds);
IOSTATS_TIMER_GUARD(allocate_nanos); IOSTATS_TIMER_GUARD(allocate_nanos);
int alloc_status = 0; int alloc_status = 0;
@ -1031,8 +1031,8 @@ Status PosixWritableFile::Allocate(uint64_t offset, uint64_t len) {
Status PosixWritableFile::RangeSync(uint64_t offset, uint64_t nbytes) { Status PosixWritableFile::RangeSync(uint64_t offset, uint64_t nbytes) {
#ifdef ROCKSDB_RANGESYNC_PRESENT #ifdef ROCKSDB_RANGESYNC_PRESENT
assert(offset <= std::numeric_limits<off_t>::max()); assert(offset <= static_cast<uint64_t>(std::numeric_limits<off_t>::max()));
assert(nbytes <= std::numeric_limits<off_t>::max()); assert(nbytes <= static_cast<uint64_t>(std::numeric_limits<off_t>::max()));
if (sync_file_range_supported_) { if (sync_file_range_supported_) {
int ret; int ret;
if (strict_bytes_per_sync_) { if (strict_bytes_per_sync_) {

@ -192,7 +192,8 @@ int GetMaxOpenFiles() {
return -1; return -1;
} }
// protect against overflow // protect against overflow
if (no_files_limit.rlim_cur >= std::numeric_limits<int>::max()) { if (static_cast<uintmax_t>(no_files_limit.rlim_cur) >=
static_cast<uintmax_t>(std::numeric_limits<int>::max())) {
return std::numeric_limits<int>::max(); return std::numeric_limits<int>::max();
} }
return static_cast<int>(no_files_limit.rlim_cur); return static_cast<int>(no_files_limit.rlim_cur);

Loading…
Cancel
Save