From 201208cbc127f99e7643e4a72e6eafbbaa4d5ea8 Mon Sep 17 00:00:00 2001
From: Craig Small <csmall@enc.com.au>
Date: Thu, 12 May 2016 20:43:49 +1000
Subject: [PATCH] ps: Output of nwchan is a number
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

For some time with enough compilier flags I have watched the
following warning drift by:
ps/output.c: In function ‘pr_nwchan’:
ps/output.c:658:41: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
   return snprintf(outbuf, COLWID, "%x", (unsigned)rSv(WCHAN_NAME, str, pp));

nwchan is supposed to be the address of where the process is sleeping,
not the name. Besides %x is a hex number not a string hence the warning.

nwchan now prints the address, in hex and GCC is happy.
---
 ps/output.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/ps/output.c b/ps/output.c
index a8907088..5bc93f8a 100644
--- a/ps/output.c
+++ b/ps/output.c
@@ -654,8 +654,12 @@ setREL1(WCHAN_NAME)
 }
 
 static int pr_nwchan(char *restrict const outbuf, const proc_t *restrict const pp){
-setREL1(WCHAN_NAME)
-  return snprintf(outbuf, COLWID, "%x", (unsigned)rSv(WCHAN_NAME, str, pp));
+setREL1(WCHAN_ADDR)
+  if (!(rSv(WCHAN_ADDR, ul_int, pp) & 0xffffff)) {
+    memcpy(outbuf, "-",2);
+    return 1;
+  }
+  return snprintf(outbuf, COLWID, "%x", (unsigned)rSv(WCHAN_ADDR, ul_int, pp));
 }
 
 /* Terrible trunctuation, like BSD crap uses: I999 J999 K999 */