]> Savannah Git Hosting - gnulib.git/commitdiff
getopt: give accurate ambiguity diagnostic on mem exhaustion
authorPádraig Brady <P@draigBrady.com>
Wed, 18 Feb 2015 22:37:31 +0000 (22:37 +0000)
committerPádraig Brady <P@draigBrady.com>
Wed, 18 Feb 2015 22:48:38 +0000 (22:48 +0000)
* lib/getopt.c (_getopt_internal_r): The previous commit broke
out the loop too early, which could give a false indication
of ambiguous options under memory exhaustion.

lib/getopt.c

index 6474ba74c9c9ed195cbf3f60553b2d1ec461f8b1..212cbf7341074627ef9fa7440783aaab8643d9e2 100644 (file)
@@ -527,6 +527,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
                 pfound = p;
                 indfound = option_index;
               }
+            else if (ambig)
+              ; /* Taking simpler path to handling ambiguities.  */
             else if (long_only
                      || pfound->has_arg != p->has_arg
                      || pfound->flag != p->flag
@@ -539,10 +541,9 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
                 struct option_list *newp = malloc (sizeof (*newp));
                 if (newp == NULL)
                   {
-                    ambig = 1; /* Use simpler fallback message.  */
                     free_option_list (ambig_list);
                     ambig_list = NULL;
-                    break;
+                    ambig = 1; /* Use simpler fallback message.  */
                   }
                 else
 #endif