From: Simon Marchi Date: Tue, 10 Apr 2018 20:50:59 +0000 (-0400) Subject: Iterate by index in auto_load_safe_path_vec_update X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6e22e10d63addd60f39114cef81ade290b15b2c8;p=binutils-gdb.git Iterate by index in auto_load_safe_path_vec_update As reported by Jan, we get this error when building with -D_GLIBCXX_DEBUG: /usr/include/c++/7/debug/safe_iterator.h:297: Error: attempt to increment a singular iterator. Objects involved in the operation: iterator "this" @ 0x0x7fffffffd140 { type = __gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator >*, std::__cxx1998::vector >, std::allocator > > > >, std::__debug::vector >, std::allocator > > > > (mutable iterator); state = singular; references sequence with type 'std::__debug::vector >, std::allocator > > >' @ 0x0x265db40 } The bug was introduced by commit commit e80aaf6183c6692ecc167bf26cbdc53f8f1a55f0 Author: Simon Marchi Date: Fri Mar 2 23:22:06 2018 -0500 Make delim_string_to_char_ptr_vec return an std::vector The problem is that we iterate using a range-based for on a vector to which we push in the loop. Pushing to the vector invalidates the iterator used in the loop. Instead, change the code to iterate by index as was done in the previous code. gdb/ChangeLog: * auto-load.c (auto_load_safe_path_vec_update): Iterate by index. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d46ecdd1208..6ed9d6c4f69 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2018-04-10 Simon Marchi + + * auto-load.c (auto_load_safe_path_vec_update): Iterate by + index. + 2018-04-10 Pedro Alves * gdbthread.h (finish_thread_state_cleanup): Delete declaration. diff --git a/gdb/auto-load.c b/gdb/auto-load.c index e426468f5df..33d282afe83 100644 --- a/gdb/auto-load.c +++ b/gdb/auto-load.c @@ -197,20 +197,19 @@ auto_load_expand_dir_vars (const char *string) static void auto_load_safe_path_vec_update (void) { - unsigned len; - int ix; - if (debug_auto_load) fprintf_unfiltered (gdb_stdlog, _("auto-load: Updating directories of \"%s\".\n"), auto_load_safe_path); auto_load_safe_path_vec = auto_load_expand_dir_vars (auto_load_safe_path); + size_t len = auto_load_safe_path_vec.size (); /* Apply tilde_expand and gdb_realpath to each AUTO_LOAD_SAFE_PATH_VEC element. */ - for (gdb::unique_xmalloc_ptr &in_vec : auto_load_safe_path_vec) + for (size_t i = 0; i < len; i++) { + gdb::unique_xmalloc_ptr &in_vec = auto_load_safe_path_vec[i]; gdb::unique_xmalloc_ptr expanded (tilde_expand (in_vec.get ())); gdb::unique_xmalloc_ptr real_path = gdb_realpath (expanded.get ());