Re: unhelpful error message: unknown option ""

John E Hein <[email protected]>
Newsgroups gmane.comp.gnu.indent.bugs
Message-ID <[email protected]>
John E Hein wrote at 12:34 -0700 on Nov  2, 2005:
 > After updating from 2.2.6 to 2.2.9, I had a problem with the
 > --no-parameter-indentation option I was using.
 > 
 > As it turns out, it was removed in favor of using
 > just --parameter-indentation0.  The documentation was not
 > updated.  That's a different bug.

Sorry that part was a hasty guess.  So it hasn't been removed.

It turns out there is another bug, but it's the option table setup for
"nip" if BERKELEY_DEFAULTS [*] is defined.  It's missing the extra NUL
in the p_obj field.

This causes the loop in the PRO_SETTINGS case of the p_type switch in
set_options() to overrun a buffer and walk off into uncharted memory
recursively calling set_options again until it sees a double NUL in
the random memory or exits for other reasons.  In my case, it always
seems to die with "unknown option" before it gets too far.

I am running the FreeBSD port (defines BERKELEY_DEFAULTS), which is
why I noticed.

[*] The mostly duplicated initialization of the opts table with and
without BERKELEY_DEFAULTS is a design bug, IMO.

Here's a new and improved patch that includes a fix for this and the
fix for the previously reported error message bug...

--- args.c.orig	Sun Nov 10 14:02:48 2002
+++ args.c	Wed Nov  2 13:29:11 2005
@@ -230,7 +230,7 @@
     {"npcs",    PRO_BOOL,                           false,      OFF, &settings.proc_calls_space,                 &exp_pcs},
     {"nlps",    PRO_BOOL,                           false,      OFF, &settings.leave_preproc_space,              &exp_lps},
     {"nlp",     PRO_BOOL,                            true,      OFF, &settings.lineup_to_parens,                 &exp_lp},
-    {"nip",     PRO_SETTINGS,                           0, ONOFF_NA, (int *) "-ip0",                             &exp_nip},
+    {"nip",     PRO_SETTINGS,                           0, ONOFF_NA, (int *) "-ip0\0",                             &exp_nip},
     {"nhnl",    PRO_BOOL,                            true,      OFF, &settings.honour_newlines,                  &exp_hnl},
     {"nfca",    PRO_BOOL,                            true,      OFF, &settings.format_comments,                  &exp_fca},
     {"nfc1",    PRO_BOOL,                            true,      OFF, &settings.format_col1_comments,             &exp_fc1},
@@ -714,7 +714,7 @@
 
     if (!found)
     {
-        fprintf (stderr, _("indent: unknown option \"%s\"\n"), option - 1);
+        fprintf (stderr, _("indent: unknown option \"%s\"\n"), option);
         exit (invocation_error);
     }
     else
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.