This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Use gdb::byte_vector in pascal_object_print_value


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=49663d051c70e1366f9b94f586459a329e9b7053

commit 49663d051c70e1366f9b94f586459a329e9b7053
Author: Tom Tromey <tom@tromey.com>
Date:   Mon Aug 14 00:15:33 2017 -0600

    Use gdb::byte_vector in pascal_object_print_value
    
    This changes pascal_object_print_value to use a gdb::byte_vector.
    This removes a cleanup.  This change also points out how the previous
    code had a possible use-after-free bug.
    
    ChangeLog
    2017-09-09  Tom Tromey  <tom@tromey.com>
    
    	* p-valprint.c (pascal_object_print_value): Use gdb::byte_vector.

Diff:
---
 gdb/ChangeLog    |  4 ++++
 gdb/p-valprint.c | 13 +++++--------
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 2ccf4e6..fd1f360 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,9 @@
 2017-09-09  Tom Tromey  <tom@tromey.com>
 
+	* p-valprint.c (pascal_object_print_value): Use gdb::byte_vector.
+
+2017-09-09  Tom Tromey  <tom@tromey.com>
+
 	* stack.c (func_command): Use gdb::def_vector.
 
 2017-09-09  Tom Tromey  <tom@tromey.com>
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
index 1cd69cc..d12b636 100644
--- a/gdb/p-valprint.c
+++ b/gdb/p-valprint.c
@@ -38,6 +38,7 @@
 #include "cp-abi.h"
 #include "cp-support.h"
 #include "objfiles.h"
+#include "common/byte-vector.h"
 
 
 /* Decorations for Pascal.  */
@@ -730,6 +731,7 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
       const gdb_byte *base_valaddr = NULL;
       LONGEST thisoffset;
       int skip = 0;
+      gdb::byte_vector buf;
 
       if (BASETYPE_VIA_VIRTUAL (type, i))
 	{
@@ -769,20 +771,15 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
 
 	  if (boffset < 0 || boffset >= TYPE_LENGTH (type))
 	    {
-	      gdb_byte *buf;
-	      struct cleanup *back_to;
+	      buf.resize (TYPE_LENGTH (baseclass));
 
-	      buf = (gdb_byte *) xmalloc (TYPE_LENGTH (baseclass));
-	      back_to = make_cleanup (xfree, buf);
-
-	      base_valaddr = buf;
-	      if (target_read_memory (address + boffset, buf,
+	      base_valaddr = buf.data ();
+	      if (target_read_memory (address + boffset, buf.data (),
 				      TYPE_LENGTH (baseclass)) != 0)
 		skip = 1;
 	      address = address + boffset;
 	      thisoffset = 0;
 	      boffset = 0;
-	      do_cleanups (back_to);
 	    }
 	  else
 	    base_valaddr = valaddr;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]