GNU Binutils with patches for OS216
修订版 | fa3a13076c0564631c51520c96df490d55e3217d (tree) |
---|---|
时间 | 2016-11-17 09:59:43 |
作者 | Pedro Alves <palves@redh...> |
Commiter | Pedro Alves |
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:
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:
yyyy-mm-dd 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.
@@ -2568,9 +2568,8 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr, | ||
2568 | 2568 | gdb_byte *unpacked; |
2569 | 2569 | const int is_scalar = is_scalar_type (type); |
2570 | 2570 | const int is_big_endian = gdbarch_bits_big_endian (get_type_arch (type)); |
2571 | - gdb_byte *staging = NULL; | |
2571 | + std::unique_ptr<gdb_byte[]> staging; | |
2572 | 2572 | int staging_len = 0; |
2573 | - struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); | |
2574 | 2573 | |
2575 | 2574 | type = ada_check_typedef (type); |
2576 | 2575 |
@@ -2589,14 +2588,13 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr, | ||
2589 | 2588 | we do, is unpack the data into a byte-aligned buffer, and then |
2590 | 2589 | use that buffer as our object's value for resolving the type. */ |
2591 | 2590 | staging_len = (bit_size + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT; |
2592 | - staging = (gdb_byte *) malloc (staging_len); | |
2593 | - make_cleanup (xfree, staging); | |
2591 | + staging.reset (new gdb_byte[staging_len]); | |
2594 | 2592 | |
2595 | 2593 | ada_unpack_from_contents (src, bit_offset, bit_size, |
2596 | - staging, staging_len, | |
2594 | + staging.get (), staging_len, | |
2597 | 2595 | is_big_endian, has_negatives (type), |
2598 | 2596 | is_scalar); |
2599 | - type = resolve_dynamic_type (type, staging, 0); | |
2597 | + type = resolve_dynamic_type (type, staging.get (), 0); | |
2600 | 2598 | if (TYPE_LENGTH (type) < (bit_size + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT) |
2601 | 2599 | { |
2602 | 2600 | /* 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, | ||
2656 | 2654 | if (bit_size == 0) |
2657 | 2655 | { |
2658 | 2656 | memset (unpacked, 0, TYPE_LENGTH (type)); |
2659 | - do_cleanups (old_chain); | |
2660 | 2657 | return v; |
2661 | 2658 | } |
2662 | 2659 |
@@ -2665,14 +2662,13 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr, | ||
2665 | 2662 | /* Small short-cut: If we've unpacked the data into a buffer |
2666 | 2663 | of the same size as TYPE's length, then we can reuse that, |
2667 | 2664 | instead of doing the unpacking again. */ |
2668 | - memcpy (unpacked, staging, staging_len); | |
2665 | + memcpy (unpacked, staging.get (), staging_len); | |
2669 | 2666 | } |
2670 | 2667 | else |
2671 | 2668 | ada_unpack_from_contents (src, bit_offset, bit_size, |
2672 | 2669 | unpacked, TYPE_LENGTH (type), |
2673 | 2670 | is_big_endian, has_negatives (type), is_scalar); |
2674 | 2671 | |
2675 | - do_cleanups (old_chain); | |
2676 | 2672 | return v; |
2677 | 2673 | } |
2678 | 2674 |