gas/ELF: avoid below-base ref in obj_elf_parse_section_letters()
authorJan Beulich <jbeulich@suse.com>
Tue, 21 Dec 2021 08:30:03 +0000 (09:30 +0100)
committerJan Beulich <jbeulich@suse.com>
Tue, 21 Dec 2021 08:30:03 +0000 (09:30 +0100)
We would better be prepared for 'm' being the first character of the
incoming string.

gas/config/obj-elf.c

index a6087a21eb39d899a484a372d980945992740704..3a9835abcafbd376823df8e37de6ef231b86184f 100644 (file)
@@ -860,6 +860,17 @@ obj_elf_parse_section_letters (char *str, size_t len,
        {
        case 'a':
          attr |= SHF_ALLOC;
+         /* Compatibility.  */
+         if (len > 1 && str[1] == 'm')
+           {
+             attr |= SHF_MERGE;
+             str++, len--;
+             if (len > 1 && str[1] == 's')
+               {
+                 attr |= SHF_STRINGS;
+                 str++, len--;
+               }
+           }
          break;
        case 'e':
          attr |= SHF_EXCLUDE;
@@ -894,19 +905,6 @@ obj_elf_parse_section_letters (char *str, size_t len,
        case '?':
          *is_clone = true;
          break;
-       /* Compatibility.  */
-       case 'm':
-         if (*(str - 1) == 'a')
-           {
-             attr |= SHF_MERGE;
-             if (len > 1 && str[1] == 's')
-               {
-                 attr |= SHF_STRINGS;
-                 str++, len--;
-               }
-             break;
-           }
-         /* Fall through.  */
        default:
          {
            const char *bad_msg = _("unrecognized .section attribute:"