chroot: Remove always-true checks

gid_t and uid_t are unsigned types, so the values are always >= 0.

usr.sbin/chroot/chroot.c: In function 'resolve_group':
usr.sbin/chroot/chroot.c:68:55: error: comparison of unsigned expression in '>= 0' is always true [-Werror=type-limits]
   68 |         if (errno == 0 && *endp == '\0' && (gid_t)gid >= 0 && gid <= GID_MAX)
      |                                                       ^~
usr.sbin/chroot/chroot.c: In function 'resolve_user':
usr.sbin/chroot/chroot.c:87:55: error: comparison of unsigned expression in '>= 0' is always true [-Werror=type-limits]
   87 |         if (errno == 0 && *endp == '\0' && (uid_t)uid >= 0 && uid <= UID_MAX)
      |                                                       ^~

Reported by:	GCC
Fixes:		91eb4d2ba4 ("chroot: slightly cleanup")
This commit is contained in:
John Baldwin
2025-08-07 13:48:36 -04:00
parent 2d76470b70
commit 3c4b3bab19
+2 -2
View File
@@ -65,7 +65,7 @@ resolve_group(const char *group)
*/
errno = 0;
gid = strtoul(group, &endp, 0);
if (errno == 0 && *endp == '\0' && (gid_t)gid >= 0 && gid <= GID_MAX)
if (errno == 0 && *endp == '\0' && gid <= GID_MAX)
return (gid);
errx(1, "no such group '%s'", group);
@@ -84,7 +84,7 @@ resolve_user(const char *user)
errno = 0;
uid = strtoul(user, &endp, 0);
if (errno == 0 && *endp == '\0' && (uid_t)uid >= 0 && uid <= UID_MAX)
if (errno == 0 && *endp == '\0' && uid <= UID_MAX)
return (uid);
errx(1, "no such user '%s'", user);