From: Karel Zak Date: Mon, 30 Jan 2012 22:17:28 +0000 (+0100) Subject: libmount: fix negative returns [coverity scan] X-Git-Tag: v2.21-rc2~76 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b47b7b3afbe6aa4e619ac7bdbf3b72286cf3bcd2;p=thirdparty%2Futil-linux.git libmount: fix negative returns [coverity scan] Signed-off-by: Karel Zak --- diff --git a/libmount/src/utils.c b/libmount/src/utils.c index c4f5f9910f..0bd7c361b5 100644 --- a/libmount/src/utils.c +++ b/libmount/src/utils.c @@ -498,13 +498,14 @@ int mnt_get_uid(const char *username, uid_t *uid) int rc = -1; struct passwd pwd; struct passwd *pw; - size_t sz = sysconf(_SC_GETPW_R_SIZE_MAX); + size_t sz; + long xsz = sysconf(_SC_GETPW_R_SIZE_MAX); char *buf; if (!username || !uid) return -EINVAL; - if (sz <= 0) - sz = 16384; /* Should be more than enough */ + + sz = xsz <= 0 ? 16384 : (size_t) xsz; buf = malloc(sz); if (!buf) @@ -527,13 +528,14 @@ int mnt_get_gid(const char *groupname, gid_t *gid) int rc = -1; struct group grp; struct group *gr; - size_t sz = sysconf(_SC_GETGR_R_SIZE_MAX); + size_t sz; + long xsz = sysconf(_SC_GETGR_R_SIZE_MAX); char *buf; if (!groupname || !gid) return -EINVAL; - if (sz <= 0) - sz = 16384; /* Should be more than enough */ + + sz = xsz <= 0 ? 16384 : (size_t) xsz; buf = malloc(sz); if (!buf)