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

login
register
mail settings
Submitter Tom Tromey
Date Feb. 9, 2018, 1 p.m.
Message ID <876076wc67.fsf@tromey.com>
Download mbox | patch
Permalink /patch/25885/
State New
Headers show

Comments

Tom Tromey - Feb. 9, 2018, 1 p.m.
>>>>> "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.
Pedro Alves - Feb. 9, 2018, 1:10 p.m.
On 02/09/2018 01:00 PM, Tom Tromey wrote:
>>>>>> "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?

OK.

Thanks,
Pedro Alves

Patch

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;