From c904a764022612fa200ce17e5a6cbbaf67bef80f Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Fri, 15 Feb 2008 10:20:09 +0000 Subject: [PATCH] PR binutils/5713 * strings.c (integer_arg): Delete function. (string_min): Initialise to 4. (main): Use strtoul to parse integer arguments. Move check for an invalid string length to after all the arguments have been parsed. (usage): Use indentation to indicate that - is a another form of the --bytes= command line option. --- binutils/ChangeLog | 11 ++++++++++ binutils/strings.c | 63 ++++++------------------------------------------------ 2 files changed, 17 insertions(+), 57 deletions(-) diff --git a/binutils/ChangeLog b/binutils/ChangeLog index fafc7f6..a613879 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,14 @@ +2008-02-15 Nick Clifton + + PR binutils/5713 + * strings.c (integer_arg): Delete function. + (string_min): Initialise to 4. + (main): Use strtoul to parse integer arguments. + Move check for an invalid string length to after all the arguments + have been parsed. + (usage): Use indentation to indicate that - is a another form + of the --bytes= command line option. + 2008-02-12 Nick Clifton * dlltool.c (mcore_elf_cache_filename): Add a const qualifier to diff --git a/binutils/strings.c b/binutils/strings.c index cf4b336..40b53b8 100644 --- a/binutils/strings.c +++ b/binutils/strings.c @@ -160,7 +160,6 @@ typedef struct static void strings_a_section (bfd *, asection *, void *); static bfd_boolean strings_object_file (const char *); static bfd_boolean strings_file (char *file); -static int integer_arg (char *s); static void print_strings (const char *, FILE *, file_off, int, int, char *); static void usage (FILE *, int); static long get_char (FILE *, file_off *, int *, char **); @@ -185,7 +184,7 @@ main (int argc, char **argv) expandargv (&argc, &argv); - string_min = -1; + string_min = 4; print_addresses = FALSE; print_filenames = FALSE; datasection_only = TRUE; @@ -210,9 +209,7 @@ main (int argc, char **argv) usage (stdout, 0); case 'n': - string_min = integer_arg (optarg); - if (string_min < 1) - fatal (_("invalid number %s"), optarg); + string_min = (int) strtoul (optarg, NULL, 0); break; case 'o': @@ -262,16 +259,13 @@ main (int argc, char **argv) usage (stderr, 1); default: - if (string_min < 0) - string_min = optc - '0'; - else - string_min = string_min * 10 + optc - '0'; + string_min = (int) strtoul (argv[optind - 1] + 1, NULL, 0); break; } } - if (string_min <= 0) - string_min = 4; + if (string_min < 1) + fatal (_("invalid minimum string length %d"), string_min); switch (encoding) { @@ -666,51 +660,6 @@ print_strings (const char *filename, FILE *stream, file_off address, } } -/* Parse string S as an integer, using decimal radix by default, - but allowing octal and hex numbers as in C. */ - -static int -integer_arg (char *s) -{ - int value; - int radix = 10; - char *p = s; - int c; - - if (*p != '0') - radix = 10; - else if (*++p == 'x') - { - radix = 16; - p++; - } - else - radix = 8; - - value = 0; - while (((c = *p++) >= '0' && c <= '9') - || (radix == 16 && (c & ~40) >= 'A' && (c & ~40) <= 'Z')) - { - value *= radix; - if (c >= '0' && c <= '9') - value += c - '0'; - else - value += (c & ~40) - 'A'; - } - - if (c == 'b') - value *= 512; - else if (c == 'B') - value *= 1024; - else - p--; - - if (*p) - fatal (_("invalid integer argument %s"), s); - - return value; -} - static void usage (FILE *stream, int status) { @@ -720,7 +669,7 @@ usage (FILE *stream, int status) -a - --all Scan the entire file, not just the data section\n\ -f --print-file-name Print the name of the file before each string\n\ -n --bytes=[number] Locate & print any NUL-terminated sequence of at\n\ - - least [number] characters (default 4).\n\ + - least [number] characters (default 4).\n\ -t --radix={o,d,x} Print the location of the string in base 8, 10 or 16\n\ -o An alias for --radix=o\n\ -T --target= Specify the binary file format\n\ -- 2.7.4