This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Avoid indexing std::vector past the end
- From: Simon Marchi <simon dot marchi at polymtl dot ca>
- To: Ruslan Kabatsayev <b7 dot 10110111 at gmail dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Sat, 30 Dec 2017 20:31:05 -0500
- Subject: Re: [PATCH] Avoid indexing std::vector past the end
- Authentication-results: sourceware.org; auth=none
- References: <1514662273-27858-1-git-send-email-b7.10110111@gmail.com>
On 2017-12-30 14:31, Ruslan Kabatsayev wrote:
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.
Hi Ruslan,
The patch LGTM, with a nit I missed the first time. Please push with
that fixed.
---
gdb/psymtab.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index c87ef25..c622f4c 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -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;
Space before parentheses, here and in the other lines.
Thanks,
Simon