Avoid indexing std::vector past the end
authorRuslan Kabatsayev <b7.10110111@gmail.com>
Sat, 30 Dec 2017 19:14:41 +0000 (22:14 +0300)
committerRuslan Kabatsayev <b7.10110111@gmail.com>
Sun, 31 Dec 2017 08:55:19 +0000 (11:55 +0300)
The code here wants to find address of an element, and often this
element is one past the end of std::vector. Dereferencing that element
leads to undefined behavior, so it's better to simply use pointer
arithmetic instead of taking address of invalid dereference.

gdb/ChangeLog:

* psymtab.c (recursively_search_psymtabs): Use pointer arithmetic
instead of dereferencing std::vector past the end.

gdb/ChangeLog
gdb/psymtab.c

index edb3cd452fcf1941a570aba06492f04122fd5557..aaadf142a4641ecd3feb26bc1dfa83dcc19e713c 100644 (file)
@@ -1,3 +1,8 @@
+2017-12-31  Ruslan Kabatsayev  <b7.10110111@gmail.com>
+
+       * psymtab.c (recursively_search_psymtabs): Use pointer arithmetic
+       instead of dereferencing std::vector past the end.
+
 2017-12-30  Simon Marchi  <simon.marchi@ericsson.com>
 
        * common/diagnostics.h
index c87ef25d612c0e9413e652416ab795f173a0dcd1..1271e1829684f3369bb5009f9f9019cd3a8e7237 100644 (file)
@@ -1337,21 +1337,21 @@ recursively_search_psymtabs
     }
 
   partial_symbol **gbound
-    = &objfile->global_psymbols[ps->globals_offset + ps->n_global_syms];
+    = objfile->global_psymbols.data () + ps->globals_offset + ps->n_global_syms;
   partial_symbol **sbound
-    = &objfile->static_psymbols[ps->statics_offset + ps->n_static_syms];
+    = objfile->static_psymbols.data () + ps->statics_offset + ps->n_static_syms;
   partial_symbol **bound = gbound;
 
   /* Go through all of the symbols stored in a partial
      symtab in one loop.  */
-  partial_symbol **psym = &objfile->global_psymbols[ps->globals_offset];
+  partial_symbol **psym = objfile->global_psymbols.data () + ps->globals_offset;
   while (keep_going)
     {
       if (psym >= bound)
        {
          if (bound == gbound && ps->n_static_syms != 0)
            {
-             psym = &objfile->static_psymbols[ps->statics_offset];
+             psym = objfile->static_psymbols.data () + ps->statics_offset;
              bound = sbound;
            }
          else
This page took 0.03483 seconds and 4 git commands to generate.