diff options
author | Karel Zak | 2012-01-30 23:17:28 +0100 |
---|---|---|
committer | Karel Zak | 2012-01-30 23:17:53 +0100 |
commit | b47b7b3afbe6aa4e619ac7bdbf3b72286cf3bcd2 (patch) | |
tree | 11cbba335ed26b38932bf2e9c93f7b34605d7be0 /libmount/src/utils.c | |
parent | libmount: fix checked-return [coverity scan] (diff) | |
download | kernel-qcow2-util-linux-b47b7b3afbe6aa4e619ac7bdbf3b72286cf3bcd2.tar.gz kernel-qcow2-util-linux-b47b7b3afbe6aa4e619ac7bdbf3b72286cf3bcd2.tar.xz kernel-qcow2-util-linux-b47b7b3afbe6aa4e619ac7bdbf3b72286cf3bcd2.zip |
libmount: fix negative returns [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/utils.c')
-rw-r--r-- | libmount/src/utils.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/libmount/src/utils.c b/libmount/src/utils.c index c4f5f9910..0bd7c361b 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) |