]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: fix negative returns [coverity scan]
authorKarel Zak <kzak@redhat.com>
Mon, 30 Jan 2012 22:17:28 +0000 (23:17 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 30 Jan 2012 22:17:53 +0000 (23:17 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/utils.c

index c4f5f9910fcc490e0631c25d8b1f3e3bb5f4c3b0..0bd7c361b551a94c3c03cda45a5342e68bdc6521 100644 (file)
@@ -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)