Re: [RFA 7/9] Use std::vector in find_source_lines

Tom Tromey
2018-02-09T13:00:32Z

>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> + end = &data[size];

Andre pointed out that this is possibly fishy, so I think perhaps the
appended should go in. Ok?

Tom

commit 4e40d3c76f0e14aea171c9ef7447c78defee8a74
Author: Tom Tromey <tom@tromey.com>
Date: Fri Feb 9 05:58:46 2018 -0700

Don't reference past the end of the vector

An earlier change made find_source_lines read:

end = &data[size];

However, since 'size' is the size of the vector, this seems fishy.
More obviously ok is to compute the end of the data directly:

end = data.data () + size;

2018-02-09 Tom Tromey <tom@tromey.com>

* source.c (find_source_lines): Don't reference past the end of
the vector.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3e5b324472..d07da95027 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2018-02-09 Tom Tromey <tom@tromey.com>
+
+ * source.c (find_source_lines): Don't reference past the end of
+ the vector.
+
2018-02-09 Joel Brobecker <brobecker@adacore.com>

* NEWS <Changes in GDB 8.1>: Clarify that "rbreak" is a new
diff --git a/gdb/source.c b/gdb/source.c
index 9eec58febd..009bec5285 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -1219,7 +1219,7 @@ find_source_lines (struct symtab *s, int desc)
size = myread (desc, data.data (), size);
if (size < 0)
perror_with_name (symtab_to_filename_for_display (s));
- end = &data[size];
+ end = data.data () + size;
p = &data[0];
line_charpos[0] = 0;
nlines = 1;