Skip to content

Fix warnings about mixing signed and unsigned types in comparisons

Piotr Batko requested to merge pbatko/fix-rocksdb-warnings into develop

G++ 9.4.0 and newer reports warnings listed below.

In all cases it's comparison like:

assert(unsigned_value <= signed_maximum);

And signed_maximum always can be represented as unsigned type. So I add casts:

assert(unsigned_value <= static_cast<right_unsigned_type>(signed_maximum));

Reported warnings:

/home/dev/workspace/hive/libraries/vendor/rocksdb/port/port_posix.cc: In function ‘int rocksdb::port::GetMaxOpenFiles()’:
/home/dev/workspace/hive/libraries/vendor/rocksdb/port/port_posix.cc:180:31: error: comparison of integer expressions of different signedness: ‘rlim_t’ {aka ‘long unsigned int’} and ‘int’ [-Werror=sign-compare]
  180 |   if (no_files_limit.rlim_cur >= std::numeric_limits<int>::max()) {
      |       ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
libraries/vendor/rocksdb/CMakeFiles/rocksdb.dir/build.make:5222: recipe for target 'libraries/vendor/rocksdb/CMakeFiles/rocksdb.dir/port/port_posix.cc.o' failed
make[2]: *** [libraries/vendor/rocksdb/CMakeFiles/rocksdb.dir/port/port_posix.cc.o] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from /home/dev/workspace/hive/libraries/vendor/rocksdb/util/sync_point.h:7,
                 from /home/dev/workspace/hive/libraries/vendor/rocksdb/env/posix_logger.h:30,
                 from /home/dev/workspace/hive/libraries/vendor/rocksdb/env/io_posix.cc:30:
/home/dev/workspace/hive/libraries/vendor/rocksdb/env/io_posix.cc: In member function ‘virtual rocksdb::Status rocksdb::PosixMmapFile::Allocate(uint64_t, uint64_t)’:
/home/dev/workspace/hive/libraries/vendor/rocksdb/env/io_posix.cc:712:17: error: comparison of integer expressions of different signedness: ‘uint64_t’ {aka ‘long unsigned int’} and ‘long int’ [-Werror=sign-compare]
  712 |   assert(offset <= std::numeric_limits<off_t>::max());
      |          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/dev/workspace/hive/libraries/vendor/rocksdb/env/io_posix.cc:713:14: error: comparison of integer expressions of different signedness: ‘uint64_t’ {aka ‘long unsigned int’} and ‘long int’ [-Werror=sign-compare]
  713 |   assert(len <= std::numeric_limits<off_t>::max());
      |          ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/dev/workspace/hive/libraries/vendor/rocksdb/env/io_posix.cc: In member function ‘virtual rocksdb::Status rocksdb::PosixWritableFile::PositionedAppend(const rocksdb::Slice&, uint64_t)’:
/home/dev/workspace/hive/libraries/vendor/rocksdb/env/io_posix.cc:784:17: error: comparison of integer expressions of different signedness: ‘uint64_t’ {aka ‘long unsigned int’} and ‘long int’ [-Werror=sign-compare]
  784 |   assert(offset <= std::numeric_limits<off_t>::max());
      |          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/dev/workspace/hive/libraries/vendor/rocksdb/env/io_posix.cc: In member function ‘virtual rocksdb::Status rocksdb::PosixWritableFile::Allocate(uint64_t, uint64_t)’:
/home/dev/workspace/hive/libraries/vendor/rocksdb/env/io_posix.cc:928:17: error: comparison of integer expressions of different signedness: ‘uint64_t’ {aka ‘long unsigned int’} and ‘long int’ [-Werror=sign-compare]
  928 |   assert(offset <= std::numeric_limits<off_t>::max());
      |          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/dev/workspace/hive/libraries/vendor/rocksdb/env/io_posix.cc:929:14: error: comparison of integer expressions of different signedness: ‘uint64_t’ {aka ‘long unsigned int’} and ‘long int’ [-Werror=sign-compare]
  929 |   assert(len <= std::numeric_limits<off_t>::max());
      |          ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/dev/workspace/hive/libraries/vendor/rocksdb/env/io_posix.cc: In member function ‘virtual rocksdb::Status rocksdb::PosixWritableFile::RangeSync(uint64_t, uint64_t)’:
/home/dev/workspace/hive/libraries/vendor/rocksdb/env/io_posix.cc:950:17: error: comparison of integer expressions of different signedness: ‘uint64_t’ {aka ‘long unsigned int’} and ‘long int’ [-Werror=sign-compare]
  950 |   assert(offset <= std::numeric_limits<off_t>::max());
      |          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/dev/workspace/hive/libraries/vendor/rocksdb/env/io_posix.cc:951:17: error: comparison of integer expressions of different signedness: ‘uint64_t’ {aka ‘long unsigned int’} and ‘long int’ [-Werror=sign-compare]
  951 |   assert(nbytes <= std::numeric_limits<off_t>::max());
      |          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Merge request reports