]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix latent bug in ada-lang.c:remove_extra_symbols
authorTom Tromey <tromey@adacore.com>
Tue, 16 Jun 2020 17:28:23 +0000 (11:28 -0600)
committerTom Tromey <tromey@adacore.com>
Wed, 9 Sep 2020 18:48:27 +0000 (12:48 -0600)
I believe ada-lang.c:remove_extra_symbols has a latent bug.  This
function loops over a vector of symbols, removing duplicates according
to some criteria.

At the end of the loop it does:

      if (remove_p)
syms->erase (syms->begin () + i);
      i += 1;

However, this seems wrong to me -- when removing the i'th element,
this code still increments "i", thus skipping an element.

At first I thought this was a regression from the patches to remove
cleanups from ada-lang.c (this was when std::vector was introduced);
but I found that instead the bug seems to be older:

       if (remove_p)
         {
           for (j = i + 1; j < nsyms; j += 1)
             syms[j - 1] = syms[j];
           nsyms -= 1;
         }

       i += 1;

No test, as I don't know how to write one.

As this is Ada-specific, and was already reviewed internally by Joel,
I am checking it in.

gdb/ChangeLog
2020-09-09  Tom Tromey  <tromey@adacore.com>

* ada-lang.c (remove_extra_symbols): Do not increment when
removing an element

gdb/ChangeLog
gdb/ada-lang.c

index c8d46901c9fdc393bf2c1ae88981cbbedaf7edf5..b63fe897fdd3b60fc7293821100c80b887968c21 100644 (file)
@@ -1,3 +1,8 @@
+2020-09-09  Tom Tromey  <tromey@adacore.com>
+
+       * ada-lang.c (remove_extra_symbols): Do not increment when
+       removing an element
+
 2020-09-08  Tom Tromey  <tromey@adacore.com>
 
        * gdb_bfd.c (gdb_bfd_open): Call bfd_fopen when fstat fails.
index e405cd23d211a1f5d514aa2c98790486582326e8..f13866ed58fa5497a0f82ea3a49c653a1cef2f79 100644 (file)
@@ -5047,8 +5047,8 @@ remove_extra_symbols (std::vector<struct block_symbol> *syms)
       
       if (remove_p)
        syms->erase (syms->begin () + i);
-
-      i += 1;
+      else
+       i += 1;
     }
 
   /* If all the remaining symbols are identical enumerals, then