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]

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


This patches changes linux-tdep.c so that the buffer used to write
note sections when generating a core file is zero-initialized.  This
way, bytes that are not collected won't contain random
data (e.g. padding bytes).

gdb/ChangeLog:
YYYY-MM-DD  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* linux-tdep.c (linux_collect_regset_section_cb): Use
	std::vector<char> instead of char * for buf.  Remove xfree.
---
 gdb/linux-tdep.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index 3cfa2a5aa4..f4edab33ea 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -1583,7 +1583,7 @@ linux_collect_regset_section_cb (const char *sect_name, int size,
 				 const struct regset *regset,
 				 const char *human_name, void *cb_data)
 {
-  char *buf;
+  std::vector<char> buf (size);
   struct linux_collect_regset_section_cb_data *data
     = (struct linux_collect_regset_section_cb_data *) cb_data;
 
@@ -1592,19 +1592,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;
-- 
2.13.6


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