summaryrefslogtreecommitdiff
path: root/libbb/appletlib.c
diff options
context:
space:
mode:
authorDenys Vlasenko2009-05-19 18:01:42 +0200
committerDenys Vlasenko2009-05-19 18:01:42 +0200
commit0149f02a7245910e6d96463432ed8dfe49b878f3 (patch)
tree47935cf0d2f71c2f381d23e70e4c1e41a72afc5c /libbb/appletlib.c
parent5e61115ea45c621867941e52e6ac016680415656 (diff)
downloadbusybox-0149f02a7245910e6d96463432ed8dfe49b878f3.zip
busybox-0149f02a7245910e6d96463432ed8dfe49b878f3.tar.gz
appletlib.c: prevent applet list overflowing screen
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/appletlib.c')
-rw-r--r--libbb/appletlib.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 8f3729f..7b3f27c 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -633,15 +633,14 @@ static int busybox_main(char **argv)
if (!argv[1]) {
/* Called without arguments */
const char *a;
- unsigned col, output_width;
+ int col;
+ unsigned output_width;
help:
output_width = 80;
if (ENABLE_FEATURE_AUTOWIDTH) {
/* Obtain the terminal width */
get_terminal_width_height(0, &output_width, NULL);
}
- /* leading tab and room to wrap */
- output_width -= MAX_APPLET_NAME_LEN + 8;
dup2(1, 2);
full_write2_str(bb_banner); /* reuse const string... */
@@ -661,17 +660,23 @@ static int busybox_main(char **argv)
"Currently defined functions:\n");
col = 0;
a = applet_names;
+ /* prevent last comma to be in the very last pos */
+ output_width--;
while (*a) {
- int len;
- if (col > output_width) {
+ int len2 = strlen(a) + 2;
+ if (col >= (int)output_width - len2) {
full_write2_str(",\n");
col = 0;
}
- full_write2_str(col ? ", " : "\t");
+ if (col == 0) {
+ col = 6;
+ full_write2_str("\t");
+ } else {
+ full_write2_str(", ");
+ }
full_write2_str(a);
- len = strlen(a);
- col += len + 2;
- a += len + 1;
+ col += len2;
+ a += len2 - 1;
}
full_write2_str("\n\n");
return 0;