public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFA 7/9] Use std::vector in find_source_lines
Date: Fri, 09 Feb 2018 13:00:00 -0000	[thread overview]
Message-ID: <876076wc67.fsf@tromey.com> (raw)
In-Reply-To: <20180207220434.6045-8-tom@tromey.com> (Tom Tromey's message of	"Wed, 7 Feb 2018 15:04:32 -0700")

>>>>> "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;

  reply	other threads:[~2018-02-09 13:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-07 22:04 [RFA 0/9] more cleanup removal Tom Tromey
2018-02-07 22:04 ` [RFA 8/9] Use unique_xmalloc_ptr in build_id_to_debug_bfd Tom Tromey
2018-02-07 22:04 ` [RFA 9/9] Remove cleanups from solib.c Tom Tromey
2018-02-07 22:04 ` [RFA 1/9] Remove a cleanup from gdbserver Tom Tromey
2018-02-07 22:04 ` [RFA 7/9] Use std::vector in find_source_lines Tom Tromey
2018-02-09 13:00   ` Tom Tromey [this message]
2018-02-09 13:11     ` Pedro Alves
2018-02-07 22:04 ` [RFA 5/9] Use std::string in maybe_expand Tom Tromey
2018-02-07 22:04 ` [RFA 6/9] Remove cleanups from macro_define_command Tom Tromey
2018-02-07 22:04 ` [RFA 2/9] Remove make_cleanup_restore_current_thread from gdbserver Tom Tromey
2018-02-07 22:04 ` [RFA 3/9] Return unique_xmalloc_ptr from macro scope functions Tom Tromey
2018-02-07 22:04 ` [RFA 4/9] Class-ify macro_buffer Tom Tromey
2018-02-08 16:42 ` [RFA 0/9] more cleanup removal Pedro Alves
2018-02-08 18:45   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=876076wc67.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).