From 9772731ad9281081b890d5875747bfad1f87ec98 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Tue, 30 Dec 2025 09:58:00 +0100 Subject: [PATCH] Fix unsigned comparison warnings in chown() Original warnings: src/filefunc.cpp:756:12: error: comparison of unsigned expression in '< 0' is always false [-Werror=type-limits] src/filefunc.cpp:758:12: error: comparison of unsigned expression in '< 0' is always false [-Werror=type-limits] src/filefunc.cpp:759:12: error: comparison of unsigned expression in '< 0' is always false [-Werror=type-limits] The uid_t and gid_t types are unsigned, so comparisons like 'uid < 0' are always false. Changed to use static_cast(-1) and static_cast(-1) to check for sentinel values. --- src/filefunc.cpp | 18 +++++++++++------- 1 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/filefunc.cpp b/src/filefunc.cpp index fbb8903..49358ff 100644 --- a/src/filefunc.cpp +++ b/src/filefunc.cpp @@ -752,13 +752,17 @@ bool chmod(const std::string& path, int mode) */ bool chown(const std::string& path, const I2n::User& user, const I2n::Group& group) { - uid_t uid= user.Uid; - if (uid<0) return false; - gid_t gid= group.Gid; - if (gid<0) gid= user.Gid; - if (gid<0) return false; - int res= ::chown( path.c_str(), uid, gid); - return (res==0); + uid_t uid = user.Uid; + gid_t gid = group.Gid; + // Use sentinel value check for unsigned types + if (uid == static_cast(-1)) + return false; + if (gid == static_cast(-1)) + gid = user.Gid; + if (gid == static_cast(-1)) + return false; + int res = ::chown(path.c_str(), uid, gid); + return (res == 0); } // eo chown(const std::string&,const User&,const Group&) /** -- 1.7.1