]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Fix sign-compare warning src/InodeCache.cpp on FreeBSD (#1331)
authorPhilipp Storz <philipp.storz@bareos.com>
Mon, 16 Oct 2023 19:02:55 +0000 (21:02 +0200)
committerGitHub <noreply@github.com>
Mon, 16 Oct 2023 19:02:55 +0000 (21:02 +0200)
As on FreeBSD 13.2 statfs.f_bavail is signed, InodeCache.cpp cannot be compiled
but gets a sign-compare warning:

  src/InodeCache.cpp:409:30: error: comparison of integers of different signs:
    'long' and 'unsigned long' [-Werror,-Wsign-compare]
      if (buf.f_bavail * 512 < k_min_fs_mib_left * 1024 * 1024) {
          ~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1 error generated.

The problem is avoided by using static_cast to uint64_t.

src/InodeCache.cpp

index 69c6dcabf0326759f61537a8ad2366ff014c84e8..c86c668379c502484fb7d73dd0512387a6806931 100644 (file)
@@ -416,7 +416,8 @@ InodeCache::initialize()
         LOG("fstatfs failed: {}", strerror(errno));
         return false;
       }
-      if (buf.f_bavail * 512 < k_min_fs_mib_left * 1024 * 1024) {
+      if (static_cast<uint64_t>(buf.f_bavail) * 512
+          < k_min_fs_mib_left * 1024 * 1024) {
         LOG("Filesystem has less than {} MiB free space, not using inode cache",
             k_min_fs_mib_left);
         return false;