summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2015-02-10 11:16:05 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2015-02-10 11:16:05 +0000
commit4c5fdb9794cfa6b613c02cb45ec5732ecc073e29 (patch)
tree6e4cb97d15ab8259d0a85c6ce983c7a4d31de736
parentadcd0fb649d7c7de4a742078cee875c4720d3cfe (diff)
Fix -d output of smaller than 64 bit values on big-endian systems.
ok mpi@ tedu@
-rw-r--r--usr.sbin/pstat/pstat.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/usr.sbin/pstat/pstat.c b/usr.sbin/pstat/pstat.c
index 2db691b82bd..6e9224b6e6b 100644
--- a/usr.sbin/pstat/pstat.c
+++ b/usr.sbin/pstat/pstat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pstat.c,v 1.97 2015/01/16 06:40:19 deraadt Exp $ */
+/* $OpenBSD: pstat.c,v 1.98 2015/02/10 11:16:04 miod Exp $ */
/* $NetBSD: pstat.c,v 1.27 1996/10/23 22:50:06 cgd Exp $ */
/*-
@@ -55,6 +55,7 @@
#include <sys/sysctl.h>
#include <stdint.h>
+#include <endian.h>
#include <err.h>
#include <kvm.h>
#include <limits.h>
@@ -215,7 +216,7 @@ main(int argc, char *argv[])
if (dformat) {
struct nlist *nl;
int longformat = 0, stringformat = 0, error = 0, n;
- int mask = ~0;
+ uint32_t mask = ~0;
char format[10], buf[1024];
n = strlen(dformat);
@@ -275,7 +276,7 @@ main(int argc, char *argv[])
kvm_nlist(kd, nl);
globalnl = nl;
for (i = 0; i < argc; i++) {
- long long v;
+ uint64_t v;
printf("%s ", argv[i]);
if (!nl[i].n_value && argv[i][0] == '0') {
@@ -299,8 +300,22 @@ main(int argc, char *argv[])
printf(format, &buf);
else if (longformat)
printf(format, v);
- else
- printf(format, ((int)v) & mask);
+ else {
+#if BYTE_ORDER == BIG_ENDIAN
+ switch (mask) {
+ case 0xff:
+ v >>= 8;
+ /* FALLTHROUGH */
+ case 0xffff:
+ v >>= 16;
+ /* FALLTHROUGH */
+ case 0xffffffff:
+ v >>= 32;
+ break;
+ }
+#endif
+ printf(format, ((uint32_t)v) & mask);
+ }
}
printf("\n");
}