]> git.armaanb.net Git - slock.git/commitdiff
Only check errno if getpwuid() fails
authorsin <sin@2f30.org>
Wed, 9 Jul 2014 13:40:49 +0000 (14:40 +0100)
committersin <sin@2f30.org>
Wed, 9 Jul 2014 13:41:32 +0000 (14:41 +0100)
Checking errno otherwise is unspecified.

slock.c

diff --git a/slock.c b/slock.c
index aedee2e8eceac44bc60304424bbcece4b32f6269..399386bd31fc3f16bb39bc59e556e72d72c9ee28 100644 (file)
--- a/slock.c
+++ b/slock.c
@@ -67,10 +67,12 @@ getpw(void) { /* only run as root */
 
        errno = 0;
        pw = getpwuid(getuid());
-       if (errno)
-               die("slock: getpwuid: %s\n", strerror(errno));
-       else if (!pw)
-               die("slock: cannot retrieve password entry (make sure to suid or sgid slock)\n");
+       if (!pw) {
+               if (errno)
+                       die("slock: getpwuid: %s\n", strerror(errno));
+               else
+                       die("slock: cannot retrieve password entry (make sure to suid or sgid slock)\n");
+       }
        endpwent();
        rval =  pw->pw_passwd;