[v2,01/12] Zero-initialize linux note sections
Commit Message
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(-)
Comments
>>>>> "Pedro" == Pedro Franco de Carvalho <pedromfc@linux.ibm.com> writes:
Pedro> This patches changes linux-tdep.c so that the buffer used to write
Pedro> note sections when generating a core file is zero-initialized. This
Pedro> way, bytes that are not collected won't contain random
Pedro> data (e.g. padding bytes).
Pedro> - char *buf;
Pedro> + std::vector<char> buf (size);
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
@@ -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;