---
 toys/posix/ps.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index 079bdbd6..eff980f3 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -811,10 +811,9 @@ static int get_ps(struct dirtree *new)
     sprintf(buf, "%lld/statm", slot[SLOT_tid]);
     if (!readfileat(fd, buf, buf, &temp)) *buf = 0;

-    // Skip redundant RSS field, we got it from stat
-    for (s = buf, i=0; i<3; i++)
-      if (!sscanf(s, " %lld%n", slot+SLOT_vsz+i/2, &j)) slot[SLOT_vsz+i/2] = 0;
-      else s += j;
+    // Skip redundant RSS field, we got it from stat.
+    slot[SLOT_vsz] = slot[SLOT_shr] = 0;
+    sscanf(buf, "%lld %*d %lld", &slot[SLOT_vsz], &slot[SLOT_shr]);
   }

   // Do we need to read "exe"?
-- 
2.20.1.611.gfbb209baf1-goog
From 2d2c6ceb450f2b6a658d10e6110ce92d5765754d Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Thu, 7 Feb 2019 13:41:42 -0800
Subject: [PATCH] ps, top: fix VIRT and SHR fields.

---
 toys/posix/ps.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index 079bdbd6..eff980f3 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -811,10 +811,9 @@ static int get_ps(struct dirtree *new)
     sprintf(buf, "%lld/statm", slot[SLOT_tid]);
     if (!readfileat(fd, buf, buf, &temp)) *buf = 0;
 
-    // Skip redundant RSS field, we got it from stat
-    for (s = buf, i=0; i<3; i++)
-      if (!sscanf(s, " %lld%n", slot+SLOT_vsz+i/2, &j)) slot[SLOT_vsz+i/2] = 0;
-      else s += j;
+    // Skip redundant RSS field, we got it from stat.
+    slot[SLOT_vsz] = slot[SLOT_shr] = 0;
+    sscanf(buf, "%lld %*d %lld", &slot[SLOT_vsz], &slot[SLOT_shr]);
   }
 
   // Do we need to read "exe"?
-- 
2.20.1.611.gfbb209baf1-goog

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to