* [PATCH] Avoid indexing std::vector past the end
@ 2017-12-30 19:31 Ruslan Kabatsayev
2017-12-31 1:31 ` Simon Marchi
0 siblings, 1 reply; 2+ messages in thread
From: Ruslan Kabatsayev @ 2017-12-30 19:31 UTC (permalink / raw)
To: gdb-patches; +Cc: Ruslan Kabatsayev
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/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;
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
--
1.7.10.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Avoid indexing std::vector past the end
2017-12-30 19:31 [PATCH] Avoid indexing std::vector past the end Ruslan Kabatsayev
@ 2017-12-31 1:31 ` Simon Marchi
0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2017-12-31 1:31 UTC (permalink / raw)
To: Ruslan Kabatsayev; +Cc: gdb-patches
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-12-31 1:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-30 19:31 [PATCH] Avoid indexing std::vector past the end Ruslan Kabatsayev
2017-12-31 1:31 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).