• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

修订版fa3a13076c0564631c51520c96df490d55e3217d (tree)
时间2016-11-17 09:59:43
作者Pedro Alves <palves@redh...>
CommiterPedro Alves

Log Message

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:
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.

更改概述

差异

--- 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,
25682568 gdb_byte *unpacked;
25692569 const int is_scalar = is_scalar_type (type);
25702570 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;
25722572 int staging_len = 0;
2573- struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
25742573
25752574 type = ada_check_typedef (type);
25762575
@@ -2589,14 +2588,13 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr,
25892588 we do, is unpack the data into a byte-aligned buffer, and then
25902589 use that buffer as our object's value for resolving the type. */
25912590 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]);
25942592
25952593 ada_unpack_from_contents (src, bit_offset, bit_size,
2596- staging, staging_len,
2594+ staging.get (), staging_len,
25972595 is_big_endian, has_negatives (type),
25982596 is_scalar);
2599- type = resolve_dynamic_type (type, staging, 0);
2597+ type = resolve_dynamic_type (type, staging.get (), 0);
26002598 if (TYPE_LENGTH (type) < (bit_size + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT)
26012599 {
26022600 /* 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,
26562654 if (bit_size == 0)
26572655 {
26582656 memset (unpacked, 0, TYPE_LENGTH (type));
2659- do_cleanups (old_chain);
26602657 return v;
26612658 }
26622659
@@ -2665,14 +2662,13 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr,
26652662 /* Small short-cut: If we've unpacked the data into a buffer
26662663 of the same size as TYPE's length, then we can reuse that,
26672664 instead of doing the unpacking again. */
2668- memcpy (unpacked, staging, staging_len);
2665+ memcpy (unpacked, staging.get (), staging_len);
26692666 }
26702667 else
26712668 ada_unpack_from_contents (src, bit_offset, bit_size,
26722669 unpacked, TYPE_LENGTH (type),
26732670 is_big_endian, has_negatives (type), is_scalar);
26742671
2675- do_cleanups (old_chain);
26762672 return v;
26772673 }
26782674