diff options
author | Mike Barcroft <mike@FreeBSD.org> | 2002-06-09 00:46:24 +0000 |
---|---|---|
committer | Mike Barcroft <mike@FreeBSD.org> | 2002-06-09 00:46:24 +0000 |
commit | f3a09c6c9bfd84fb510e218c61cfe345f8c1cf73 (patch) | |
tree | a60faf97caf5fd96dec0e80cc9446dfc5d7f52f7 /bin/realpath/realpath.c | |
parent | 60f9b09d2612ecae15f5de12a0e96ffd2c987d1d (diff) | |
download | src-f3a09c6c9bfd84fb510e218c61cfe345f8c1cf73.tar.gz src-f3a09c6c9bfd84fb510e218c61cfe345f8c1cf73.zip |
Check the return value of getcwd() to avoid printf()ing a NULL. Mark
usage() as __dead2 to avoid a GCC warning.
Spotted by: keramida
Notes
Notes:
svn path=/head/; revision=98057
Diffstat (limited to 'bin/realpath/realpath.c')
-rw-r--r-- | bin/realpath/realpath.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/bin/realpath/realpath.c b/bin/realpath/realpath.c index 2cd9e6036e86..57cbb971cc43 100644 --- a/bin/realpath/realpath.c +++ b/bin/realpath/realpath.c @@ -41,7 +41,7 @@ __FBSDID("$FreeBSD$"); #include <stdlib.h> #include <unistd.h> -static void usage(void); +static void usage(void) __dead2; int main(int argc, char *argv[]) @@ -49,9 +49,10 @@ main(int argc, char *argv[]) char buf[PATH_MAX]; char *p; - if (argc == 1) - p = getcwd(NULL, 0); - else if (argc == 2) { + if (argc == 1) { + if ((p = getcwd(NULL, 0)) == NULL) + err(1, "getcwd()"); + } else if (argc == 2) { if ((p = realpath(argv[1], buf)) == NULL) err(1, "%s", argv[1]); } else |