[binutils-gdb] Fix latent bug in ada-lang.c:remove_extra_symbols

Tom Tromey tromey@sourceware.org
Wed Sep 9 19:07:31 GMT 2020


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1b788fb6e9860c2e3aa0f9bbcedcd5feded1aa6e

commit 1b788fb6e9860c2e3aa0f9bbcedcd5feded1aa6e
Author: Tom Tromey <tromey@adacore.com>
Date:   Tue Jun 16 11:28:23 2020 -0600

    Fix latent bug in ada-lang.c:remove_extra_symbols
    
    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

Diff:
---
 gdb/ChangeLog  | 5 +++++
 gdb/ada-lang.c | 4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c8d46901c9f..b63fe897fdd 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -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.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index e405cd23d21..f13866ed58f 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -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


More information about the Gdb-cvs mailing list