changeset 1501:c51a4dbe5db7

Don't segfault for --help of single.sh build of OLDTOY commands that use another command's help.
author Rob Landley <rob@landley.net>
date Sat, 27 Sep 2014 19:58:18 -0500
parents cf77c4939385
children 84922376d15c
files lib/help.c main.c
diffstat 2 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/lib/help.c	Fri Sep 26 18:49:44 2014 -0500
+++ b/lib/help.c	Sat Sep 27 19:58:18 2014 -0500
@@ -25,6 +25,11 @@
     while (i--) s += strlen(s) + 1;
     // If it's an alias, restart search for real name
     if (*s != 255) break;
+    if (!CFG_TOYBOX) {
+      s = xmprintf("See %s --help\n", ++s);
+
+      break;
+    }
     i = toy_find(++s)-toy_list;
   }
 
--- a/main.c	Fri Sep 26 18:49:44 2014 -0500
+++ b/main.c	Sat Sep 27 19:58:18 2014 -0500
@@ -26,6 +26,8 @@
 {
   int top, bottom, middle;
 
+  if (!CFG_TOYBOX) return 0;
+
   // If the name starts with "toybox" accept that as a match.  Otherwise
   // skip the first entry, which is out of order.
 
@@ -69,7 +71,7 @@
   if (CFG_TOYBOX_I18N) setlocale(LC_ALL, "C"+!!(which->flags & TOYFLAG_LOCALE));
 
   if (CFG_TOYBOX_HELP_DASHDASH && argv[1] && !strcmp(argv[1], "--help")) {
-    if (toys.which == toy_list && toys.argv[2])
+    if (CFG_TOYBOX && toys.which == toy_list && toys.argv[2])
       if (!(toys.which = toy_find(toys.argv[2]))) return;
     show_help();
     xexit();