summaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-10-27 09:03:24 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-10-27 09:03:24 +0000
commit621204bbf6750f1ba3977b43bb35375ddda6b5ae (patch)
treecd34a619db35dccb76043c1bf118d297e17ac436 /procps
parentd3d004dd3507f841745956a035fff68936378f9c (diff)
downloadbusybox-w32-621204bbf6750f1ba3977b43bb35375ddda6b5ae.tar.gz
busybox-w32-621204bbf6750f1ba3977b43bb35375ddda6b5ae.tar.bz2
busybox-w32-621204bbf6750f1ba3977b43bb35375ddda6b5ae.zip
get_terminal_width_height: do not pass insanely large values
Diffstat (limited to 'procps')
-rw-r--r--procps/ps.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/procps/ps.c b/procps/ps.c
index 0452a5046..4a917282b 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -41,7 +41,7 @@ int ps_main(int argc, char **argv)
41 /* if w is given once, GNU ps sets the width to 132, 41 /* if w is given once, GNU ps sets the width to 132,
42 * if w is given more than once, it is "unlimited" 42 * if w is given more than once, it is "unlimited"
43 */ 43 */
44 if(w_count) { 44 if (w_count) {
45 terminal_width = (w_count==1) ? 132 : INT_MAX; 45 terminal_width = (w_count==1) ? 132 : INT_MAX;
46 } else { 46 } else {
47 get_terminal_width_height(1, &terminal_width, NULL); 47 get_terminal_width_height(1, &terminal_width, NULL);
@@ -87,24 +87,24 @@ int ps_main(int argc, char **argv)
87 } 87 }
88 else 88 else
89#endif 89#endif
90 if(p->rss == 0) 90 if (p->rss == 0)
91 len = printf("%5d %-8s %s ", p->pid, p->user, p->state); 91 len = printf("%5d %-8s %s ", p->pid, p->user, p->state);
92 else 92 else
93 len = printf("%5d %-8s %6ld %s ", p->pid, p->user, p->rss, p->state); 93 len = printf("%5d %-8s %6ld %s ", p->pid, p->user, p->rss, p->state);
94 94
95 i = terminal_width-len; 95 i = terminal_width-len;
96 96
97 if(namecmd && namecmd[0]) { 97 if (namecmd && namecmd[0]) {
98 if(i < 0) 98 if (i < 0)
99 i = 0; 99 i = 0;
100 if(strlen(namecmd) > (size_t)i) 100 if (strlen(namecmd) > (size_t)i)
101 namecmd[i] = 0; 101 namecmd[i] = 0;
102 printf("%s\n", namecmd); 102 printf("%s\n", namecmd);
103 } else { 103 } else {
104 namecmd = p->short_cmd; 104 namecmd = p->short_cmd;
105 if(i < 2) 105 if (i < 2)
106 i = 2; 106 i = 2;
107 if(strlen(namecmd) > ((size_t)i-2)) 107 if (strlen(namecmd) > ((size_t)i-2))
108 namecmd[i-2] = 0; 108 namecmd[i-2] = 0;
109 printf("[%s]\n", namecmd); 109 printf("[%s]\n", namecmd);
110 } 110 }