summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBernhard Voelker <mail@bernhard-voelker.de>2016-07-27 09:33:19 +0200
committerBernhard Voelker <mail@bernhard-voelker.de>2016-07-27 21:28:49 +0200
commit558ce3044d5e22890b272b4e90f3ac0b236726a0 (patch)
tree904f9bb9fbe50eede508504e4c1b3e70c5b93e27 /src
parentf0e0f3ac924746b9436f8f54da467162b7c78ee3 (diff)
downloadcoreutils-558ce3044d5e22890b272b4e90f3ac0b236726a0.tar.xz
maint: pacify GCC 6 with -Wnull-dereference
src/id.c:249:29: error: potential null pointer dereference \ [-Werror=null-dereference] pw_name = xstrdup (pwd->pw_name); ~~~^~~~~~~~~ src/whoami.c:89:11: error: potential null pointer dereference \ [-Werror=null-dereference] puts (pw->pw_name); ~~^~~~~~~~~ * src/id.c (main): Explicitly exit with EXIT_FAILURE after an eror to help gcc-6 to detect that the dereferenced pointer is valid. * src/whoami.c (main): Likewise.
Diffstat (limited to 'src')
-rw-r--r--src/id.c5
-rw-r--r--src/whoami.c7
2 files changed, 9 insertions, 3 deletions
diff --git a/src/id.c b/src/id.c
index 218ee5a31..35cbeb564 100644
--- a/src/id.c
+++ b/src/id.c
@@ -245,7 +245,10 @@ main (int argc, char **argv)
}
}
if (pwd == NULL)
- error (EXIT_FAILURE, 0, _("%s: no such user"), quote (spec));
+ {
+ error (0, 0, _("%s: no such user"), quote (spec));
+ exit (EXIT_FAILURE);
+ }
pw_name = xstrdup (pwd->pw_name);
ruid = euid = pwd->pw_uid;
rgid = egid = pwd->pw_gid;
diff --git a/src/whoami.c b/src/whoami.c
index e58c57528..972cd5539 100644
--- a/src/whoami.c
+++ b/src/whoami.c
@@ -84,8 +84,11 @@ main (int argc, char **argv)
uid = geteuid ();
pw = (uid == NO_UID && errno ? NULL : getpwuid (uid));
if (!pw)
- error (EXIT_FAILURE, errno, _("cannot find name for user ID %lu"),
- (unsigned long int) uid);
+ {
+ error (0, errno, _("cannot find name for user ID %lu"),
+ (unsigned long int) uid);
+ exit (EXIT_FAILURE);
+ }
puts (pw->pw_name);
return EXIT_SUCCESS;
}