diff options
author | Pedro Alves <palves@redhat.com> | 2016-11-16 11:38:49 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2016-11-17 00:59:43 +0000 |
commit | 200069c74f42ffcc726b9995a46971a86286a256 (patch) | |
tree | 00be16a40f21dbbc6e2e196dd33c4ec647af9206 /gdb/ada-lang.c | |
parent | 19f1935d91bfabbe4176ffdaca95bc789b593153 (diff) | |
download | gdb-200069c74f42ffcc726b9995a46971a86286a256.zip gdb-200069c74f42ffcc726b9995a46971a86286a256.tar.gz gdb-200069c74f42ffcc726b9995a46971a86286a256.tar.bz2 |
gdb/ada-lang.c: one malloc -> unique_ptr<[]>
Switching gdb to use gnulib's C++ namespace mode reveals we're calling
malloc instead of xmalloc here:
..../src/gdb/ada-lang.c: In function ‘value* ada_value_primitive_packed_val(value*, const gdb_byte*, long int, int, int, type*)’:
..../src/gdb/ada-lang.c:2592:50: error: call to ‘malloc’ declared with attribute warning: The symbol ::malloc refers to the system function. Use gnulib::malloc instead. [-Werror]
staging = (gdb_byte *) malloc (staging_len);
^
We're unconditionaly using the result afterwards -- so it's not a case
of gracefully handling huge allocations.
Since we want to get rid of all cleanups, fix this by switching to
new[] and unique_ptr<[]> instead, while at it.
Regtested on Fedora 23.
gdb/ChangeLog:
2016-11-16 Pedro Alves <palves@redhat.com>
* ada-lang.c (ada_value_primitive_packed_val): Use unique_ptr and
new gdb_byte[] instead of malloc and cleanups.
Diffstat (limited to 'gdb/ada-lang.c')
-rw-r--r-- | gdb/ada-lang.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 73f7964..0647a9b 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -2568,9 +2568,8 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr, gdb_byte *unpacked; const int is_scalar = is_scalar_type (type); const int is_big_endian = gdbarch_bits_big_endian (get_type_arch (type)); - gdb_byte *staging = NULL; + std::unique_ptr<gdb_byte[]> staging; int staging_len = 0; - struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); type = ada_check_typedef (type); @@ -2589,14 +2588,13 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr, we do, is unpack the data into a byte-aligned buffer, and then use that buffer as our object's value for resolving the type. */ staging_len = (bit_size + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT; - staging = (gdb_byte *) malloc (staging_len); - make_cleanup (xfree, staging); + staging.reset (new gdb_byte[staging_len]); ada_unpack_from_contents (src, bit_offset, bit_size, - staging, staging_len, + staging.get (), staging_len, is_big_endian, has_negatives (type), is_scalar); - type = resolve_dynamic_type (type, staging, 0); + type = resolve_dynamic_type (type, staging.get (), 0); if (TYPE_LENGTH (type) < (bit_size + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT) { /* This happens when the length of the object is dynamic, @@ -2656,7 +2654,6 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr, if (bit_size == 0) { memset (unpacked, 0, TYPE_LENGTH (type)); - do_cleanups (old_chain); return v; } @@ -2665,14 +2662,13 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr, /* Small short-cut: If we've unpacked the data into a buffer of the same size as TYPE's length, then we can reuse that, instead of doing the unpacking again. */ - memcpy (unpacked, staging, staging_len); + memcpy (unpacked, staging.get (), staging_len); } else ada_unpack_from_contents (src, bit_offset, bit_size, unpacked, TYPE_LENGTH (type), is_big_endian, has_negatives (type), is_scalar); - do_cleanups (old_chain); return v; } |