From 3bcfb3e4bd58ff97f4a68952e1a6c1763b0e8ddc Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Wed, 19 Sep 2001 06:58:06 +0000 Subject: [PATCH] * objcopy.c (copy_main): Correct rename-section string parsing. Consolidate new_name parsing, and error messages. --- binutils/ChangeLog | 5 +++++ binutils/objcopy.c | 44 ++++++++++++++++++++------------------------ 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/binutils/ChangeLog b/binutils/ChangeLog index e25add507f..8039cc87f0 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,8 @@ +2001-09-19 Alan Modra + + * objcopy.c (copy_main): Correct rename-section string parsing. + Consolidate new_name parsing, and error messages. + 2001-09-18 Bruno Haible * addr2line.c: Don't include . diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 4be1d59d19..03ec035ce3 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -2399,47 +2399,43 @@ copy_main (argc, argv) case OPTION_RENAME_SECTION: { flagword flags; - const char * s; - char * old_name; - char * new_name; + const char *eq, *fl; + char *old_name; + char *new_name; unsigned int len; - s = strchr (optarg, '='); - if (s == NULL) + eq = strchr (optarg, '='); + if (eq == NULL) fatal (_("bad format for %s"), "--rename-section"); - len = s - optarg; + len = eq - optarg; if (len == 0) - fatal (_("no old name is %s"), "--rename-section"); + fatal (_("bad format for %s"), "--rename-section"); old_name = (char *) xmalloc (len + 1); strncpy (old_name, optarg, len); old_name[len] = 0; - s = strchr (optarg + len, ','); - if (s) + eq++; + fl = strchr (eq, ','); + if (fl) { - unsigned int new_len; - - flags = parse_flags (s + 1); - new_len = s - (optarg + len); - if (new_len == 0) - fatal (_("no new name in %s"), "--rename-section"); - new_name = (char *) xmalloc (new_len + 1); - strncpy (new_name, optarg + len, new_len); - new_name [new_len] = 0; + flags = parse_flags (fl + 1); + len = fl - eq; } else { - s = optarg + len; - len = strlen (s); - if (len == 0) - fatal (_("no new name in %s"), "--rename-section"); - new_name = (char *) xmalloc (len + 1); - strcpy (new_name, s); flags = -1; + len = strlen (eq); } + if (len == 0) + fatal (_("bad format for %s"), "--rename-section"); + + new_name = (char *) xmalloc (len + 1); + strncpy (new_name, eq, len); + new_name[len] = 0; + add_section_rename (old_name, new_name, flags); } break;