title: getopt_long_only segmentation fault
body: <p>I'm trying to use getopt_long_only to parse a command line.  My app reads a handful of command line options.</p>
  
  <p>E.g.  "app --alpha=1 --beta=2 --cecil=3"</p>
  
  <p>getopt_long_only works fine as expected as long as valid command line parameters are passed in.  But if you invoke the app with an invalid "single dashed" option at the end and at other inappropriate places, a seg fault crash occurs.  What's going on here?  Seems like getopt_long_only isn't being resilient to mistyped arguments.  Or am I invoking the function wrong?</p>
  
  <p>Example:</p>
  
  <pre><code>&gt; ./app --beta=1 -?
  starting
  index = 1   ret=0  optarg=1
  Segmentation fault
  </code></pre>
  
  <p>Code below (C++: app.cc)</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;getopt.h&gt;
  
  void ProcessCommandLineArgs(int argc, char** argv)
  {
  
      option longopts[] = {
          {"alpha", optional_argument, 0, 0},
          {"beta",  optional_argument, 0, 0},
          {"cecil", optional_argument, 0, 0}
      };
  
      int index;
      int ret;
      bool fParseError = false;
  
      while (true)
      {
          ret = ::getopt_long_only(argc, argv, "", longopts, &amp;index);
  
          if (ret &lt; 0)
          {
              break;
          }
  
          if ((ret == '?') || (ret == ':'))
          {
              fParseError = true;
              break;
          }
  
          printf("index = %d   ret=%d  optarg=%s\n", index, ret, optarg?optarg:"&lt;null&gt;");
      }
  }
  
  int main(int argc, char** argv)
  {
      printf("starting\n");
      ProcessCommandLineArgs(argc, argv);
      printf("exiting\n");
      return 0;
  }
  </code></pre>