aboutsummaryrefslogtreecommitdiff
path: root/libbb/appletlib.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-05-19 18:01:42 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-05-19 18:01:42 +0200
commit0149f02a7245910e6d96463432ed8dfe49b878f3 (patch)
tree47935cf0d2f71c2f381d23e70e4c1e41a72afc5c /libbb/appletlib.c
parent5e61115ea45c621867941e52e6ac016680415656 (diff)
downloadbusybox-w32-0149f02a7245910e6d96463432ed8dfe49b878f3.tar.gz
busybox-w32-0149f02a7245910e6d96463432ed8dfe49b878f3.tar.bz2
busybox-w32-0149f02a7245910e6d96463432ed8dfe49b878f3.zip
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 8f3729f71..7b3f27c36 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -633,15 +633,14 @@ static int busybox_main(char **argv)
633 if (!argv[1]) { 633 if (!argv[1]) {
634 /* Called without arguments */ 634 /* Called without arguments */
635 const char *a; 635 const char *a;
636 unsigned col, output_width; 636 int col;
637 unsigned output_width;
637 help: 638 help:
638 output_width = 80; 639 output_width = 80;
639 if (ENABLE_FEATURE_AUTOWIDTH) { 640 if (ENABLE_FEATURE_AUTOWIDTH) {
640 /* Obtain the terminal width */ 641 /* Obtain the terminal width */
641 get_terminal_width_height(0, &output_width, NULL); 642 get_terminal_width_height(0, &output_width, NULL);
642 } 643 }
643 /* leading tab and room to wrap */
644 output_width -= MAX_APPLET_NAME_LEN + 8;
645 644
646 dup2(1, 2); 645 dup2(1, 2);
647 full_write2_str(bb_banner); /* reuse const string... */ 646 full_write2_str(bb_banner); /* reuse const string... */
@@ -661,17 +660,23 @@ static int busybox_main(char **argv)
661 "Currently defined functions:\n"); 660 "Currently defined functions:\n");
662 col = 0; 661 col = 0;
663 a = applet_names; 662 a = applet_names;
663 /* prevent last comma to be in the very last pos */
664 output_width--;
664 while (*a) { 665 while (*a) {
665 int len; 666 int len2 = strlen(a) + 2;
666 if (col > output_width) { 667 if (col >= (int)output_width - len2) {
667 full_write2_str(",\n"); 668 full_write2_str(",\n");
668 col = 0; 669 col = 0;
669 } 670 }
670 full_write2_str(col ? ", " : "\t"); 671 if (col == 0) {
672 col = 6;
673 full_write2_str("\t");
674 } else {
675 full_write2_str(", ");
676 }
671 full_write2_str(a); 677 full_write2_str(a);
672 len = strlen(a); 678 col += len2;
673 col += len + 2; 679 a += len2 - 1;
674 a += len + 1;
675 } 680 }
676 full_write2_str("\n\n"); 681 full_write2_str("\n\n");
677 return 0; 682 return 0;