This is the mail archive of the gdb-patches@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]

Re: [PATCH v2 01/12] Zero-initialize linux note sections


Tom Tromey <tom@tromey.com> writes:

> It might be nice for future developers if there were a comment here
> explaining that this is intentionally zero-initialized.  Other spots in
> gdb use gdb::def_vector and perhaps someone might think that would be a
> worthwhile micro-optimization.
>
> Tom

Ok! I'll add the comment below.

Thanks!

diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index 3cfa2a5aa4..2bcd2390c5 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -1583,7 +1583,9 @@ linux_collect_regset_section_cb (const char *sect_name, int size,
 				 const struct regset *regset,
 				 const char *human_name, void *cb_data)
 {
-  char *buf;
+  /* This is intentionally zero-initialized by using std::vector, so
+     that any padding bytes in the core file will show as 0.  */
+  std::vector<char> buf (size);
   struct linux_collect_regset_section_cb_data *data
     = (struct linux_collect_regset_section_cb_data *) cb_data;
 
@@ -1592,19 +1594,17 @@ linux_collect_regset_section_cb (const char *sect_name, int size,
 
   gdb_assert (regset && regset->collect_regset);
 
-  buf = (char *) xmalloc (size);
-  regset->collect_regset (regset, data->regcache, -1, buf, size);
+  regset->collect_regset (regset, data->regcache, -1, buf.data (), size);
 
   /* PRSTATUS still needs to be treated specially.  */
   if (strcmp (sect_name, ".reg") == 0)
     data->note_data = (char *) elfcore_write_prstatus
       (data->obfd, data->note_data, data->note_size, data->lwp,
-       gdb_signal_to_host (data->stop_signal), buf);
+       gdb_signal_to_host (data->stop_signal), buf.data ());
   else
     data->note_data = (char *) elfcore_write_register_note
       (data->obfd, data->note_data, data->note_size,
-       sect_name, buf, size);
-  xfree (buf);
+       sect_name, buf.data (), size);
 
   if (data->note_data == NULL)
     data->abort_iteration = 1;


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