diff options
author | Tom Tromey <tom@tromey.com> | 2017-04-28 23:34:32 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-08-03 07:59:02 -0600 |
commit | 26fcd5d7572ea1bf0cc697158969749420900e0b (patch) | |
tree | 4fd942f6a9ce113d4c1733b77c3191c5fe679a47 /gdb/valarith.c | |
parent | 7c218e6c9c88cb8120adf1a7a530cfdec23aaf81 (diff) | |
download | gdb-26fcd5d7572ea1bf0cc697158969749420900e0b.zip gdb-26fcd5d7572ea1bf0cc697158969749420900e0b.tar.gz gdb-26fcd5d7572ea1bf0cc697158969749420900e0b.tar.bz2 |
Use containers to avoid cleanups
This patch introduces the use of various containers -- std::vector,
std::string, or gdb::byte_vector -- in several spots in gdb that were
using xmalloc and a cleanup.
ChangeLog
2017-08-03 Tom Tromey <tom@tromey.com>
* valops.c (search_struct_method): Use gdb::byte_vector.
* valarith.c (value_concat): Use std::vector.
* target.c (memory_xfer_partial): Use gdb::byte_vector.
(simple_search_memory): Likewise.
* printcmd.c (find_string_backward): Use gdb::byte_vector.
* mi/mi-main.c (mi_cmd_data_write_memory): Use gdb::byte_vector.
* gcore.c (gcore_copy_callback): Use gdb::byte_vector.
* elfread.c (elf_rel_plt_read): Use std::string.
* cp-valprint.c (cp_print_value): Use gdb::byte_vector.
* cli/cli-dump.c (restore_section_callback): Use
gdb::byte_vector.
Diffstat (limited to 'gdb/valarith.c')
-rw-r--r-- | gdb/valarith.c | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/gdb/valarith.c b/gdb/valarith.c index 985233c..9724aca 100644 --- a/gdb/valarith.c +++ b/gdb/valarith.c @@ -697,12 +697,9 @@ value_concat (struct value *arg1, struct value *arg2) if (TYPE_CODE (type2) == TYPE_CODE_STRING || TYPE_CODE (type2) == TYPE_CODE_CHAR) { - struct cleanup *back_to; - count = longest_to_int (value_as_long (inval1)); inval2len = TYPE_LENGTH (type2); - ptr = (char *) xmalloc (count * inval2len); - back_to = make_cleanup (xfree, ptr); + std::vector<char> ptr (count * inval2len); if (TYPE_CODE (type2) == TYPE_CODE_CHAR) { char_type = type2; @@ -711,7 +708,7 @@ value_concat (struct value *arg1, struct value *arg2) value_contents (inval2)); for (idx = 0; idx < count; idx++) { - *(ptr + idx) = inchar; + ptr[idx] = inchar; } } else @@ -720,12 +717,11 @@ value_concat (struct value *arg1, struct value *arg2) for (idx = 0; idx < count; idx++) { - memcpy (ptr + (idx * inval2len), value_contents (inval2), + memcpy (&ptr[idx * inval2len], value_contents (inval2), inval2len); } } - outval = value_string (ptr, count * inval2len, char_type); - do_cleanups (back_to); + outval = value_string (ptr.data (), count * inval2len, char_type); } else if (TYPE_CODE (type2) == TYPE_CODE_BOOL) { @@ -739,8 +735,6 @@ value_concat (struct value *arg1, struct value *arg2) else if (TYPE_CODE (type1) == TYPE_CODE_STRING || TYPE_CODE (type1) == TYPE_CODE_CHAR) { - struct cleanup *back_to; - /* We have two character strings to concatenate. */ if (TYPE_CODE (type2) != TYPE_CODE_STRING && TYPE_CODE (type2) != TYPE_CODE_CHAR) @@ -749,31 +743,29 @@ value_concat (struct value *arg1, struct value *arg2) } inval1len = TYPE_LENGTH (type1); inval2len = TYPE_LENGTH (type2); - ptr = (char *) xmalloc (inval1len + inval2len); - back_to = make_cleanup (xfree, ptr); + std::vector<char> ptr (inval1len + inval2len); if (TYPE_CODE (type1) == TYPE_CODE_CHAR) { char_type = type1; - *ptr = (char) unpack_long (type1, value_contents (inval1)); + ptr[0] = (char) unpack_long (type1, value_contents (inval1)); } else { char_type = TYPE_TARGET_TYPE (type1); - memcpy (ptr, value_contents (inval1), inval1len); + memcpy (ptr.data (), value_contents (inval1), inval1len); } if (TYPE_CODE (type2) == TYPE_CODE_CHAR) { - *(ptr + inval1len) = + ptr[inval1len] = (char) unpack_long (type2, value_contents (inval2)); } else { - memcpy (ptr + inval1len, value_contents (inval2), inval2len); + memcpy (&ptr[inval1len], value_contents (inval2), inval2len); } - outval = value_string (ptr, inval1len + inval2len, char_type); - do_cleanups (back_to); + outval = value_string (ptr.data (), inval1len + inval2len, char_type); } else if (TYPE_CODE (type1) == TYPE_CODE_BOOL) { |