This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: strings: invalid integer argument trings
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: jidanni at jidanni dot org
- Cc: bug-binutils at gnu dot org, binutils at sourceware dot org
- Date: Thu, 4 Jun 2009 17:58:07 +0930
- Subject: Re: strings: invalid integer argument trings
- References: <87hbyza49r.fsf@jidanni.org>
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