This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: strings: invalid integer argument trings


On Tue, Jun 02, 2009 at 08:05:52AM +0800, jidanni@jidanni.org wrote:
> If deprecated, then please do it properly:
> 
> $ strings --help|grep '<number>'
>   -<number>                   least [number] characters (default 4).
> $ strings -11
> strings: invalid integer argument trings
> 
> Hahaha! "trings".
> 
> $ strings --version
> GNU strings (GNU Binutils for Debian) 2.19.51.20090508

optind is incremented after an option arg is fully processed.  In the
case of '-11', the first '1' (which is seen as an option due to
decimal digits being part of the getopt_long option string) hits the
default label of the switch before optind has been incremented.

	* strings.c (main): Delay parsing of decimal digits.

Index: binutils/strings.c
===================================================================
RCS file: /cvs/src/src/binutils/strings.c,v
retrieving revision 1.44
diff -u -p -r1.44 strings.c
--- binutils/strings.c	1 Apr 2009 14:57:11 -0000	1.44
+++ binutils/strings.c	4 Jun 2009 07:43:29 -0000
@@ -158,6 +158,7 @@ main (int argc, char **argv)
   int exit_status = 0;
   bfd_boolean files_given = FALSE;
   char *s;
+  int numeric_opt = 0;
 
 #if defined (HAVE_SETLOCALE)
   setlocale (LC_ALL, "");
@@ -247,13 +248,17 @@ main (int argc, char **argv)
 	  usage (stderr, 1);
 
 	default:
-	  string_min = (int) strtoul (argv[optind - 1] + 1, &s, 0);
-	  if (s != NULL && *s != 0)
-	    fatal (_("invalid integer argument %s"), argv[optind - 1] + 1);
+	  numeric_opt = optind;
 	  break;
 	}
     }
 
+  if (numeric_opt != 0)
+    {
+      string_min = (int) strtoul (argv[numeric_opt - 1] + 1, &s, 0);
+      if (s != NULL && *s != 0)
+	fatal (_("invalid integer argument %s"), argv[numeric_opt - 1] + 1);
+    }
   if (string_min < 1)
     fatal (_("invalid minimum string length %d"), string_min);
 

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]