From 99fb10656ec74f1dd53a0df982cdc745b07a4399 Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Mon, 14 Nov 1994 07:54:06 +0000 Subject: [PATCH] Don't follow a null pointer for the reporting error if kvm_openfiles() fails. Don't ever pretend that the program is named "." and has no args. --- usr.sbin/swapinfo/swapinfo.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/usr.sbin/swapinfo/swapinfo.c b/usr.sbin/swapinfo/swapinfo.c index 7a8d12c8a4b7..811a9366688b 100644 --- a/usr.sbin/swapinfo/swapinfo.c +++ b/usr.sbin/swapinfo/swapinfo.c @@ -16,6 +16,7 @@ #include #include #include +#include struct rlist *swaplist; @@ -45,12 +46,11 @@ char **argv; static long blocksize; static int headerlen; static char *header; - char **save; kvm_t *kd; + char errbuf[_POSIX2_LINE_MAX]; /* We are trying to be simple here: */ - save = argv; while ((ch = getopt(argc, argv, "k")) != EOF) switch(ch) { case 'k': @@ -60,19 +60,13 @@ char **argv; default: usage(); } - argv += optind; - - if (!*argv) { - argv = save; - argv[0] = "."; - argv[1] = NULL; - } /* Open up /dev/kmem for reading. */ - - if ((kd = kvm_openfiles(NULL, NULL, NULL, NULL, NULL)) == (kvm_t *)0) { - fprintf (stderr, "%s: kvm_openfiles: %s\n", - argv [0], kvm_geterr(kd)); + + kd = kvm_openfiles((char *)NULL, (char *)NULL, (char *)NULL, 0, errbuf); + if (kd == NULL) { + fprintf (stderr, "%s: kvm_openfiles: %s\n", + argv [0], errbuf); exit (1); }