Skip to content

Commit b01d859

Browse files
committed
Use helper functions in get_non_char_pointer_value
To unify the access to info about allocated memory.
1 parent 6054f05 commit b01d859

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/memory-analyzer/analyze_symbol.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,13 @@ exprt gdb_value_extractort::get_non_char_pointer_value(
344344
// expected positions. Since the allocated size is over-approximation we may
345345
// end up querying pass the allocated bounds and building larger array with
346346
// meaningless values.
347-
size_t allocated_size =
348-
gdb_api.query_malloc_size(c_converter.convert(expr));
347+
const auto c_name = c_converter.convert(expr);
348+
const auto maybe_allocated_size = get_malloc_size(c_name);
349+
mp_integer allocated_size = maybe_allocated_size.has_value()
350+
? *maybe_allocated_size
351+
: gdb_api.query_malloc_size(c_name);
349352
// get the sizeof(target_type) and thus the number of elements
350-
const auto target_size_bits = pointer_offset_bits(target_type, ns);
351-
CHECK_RETURN(target_size_bits.has_value());
352-
const auto number_of_elements = allocated_size / (*target_size_bits / 8);
353+
const auto number_of_elements = allocated_size / get_type_size(target_type);
353354
if(number_of_elements > 1)
354355
{
355356
array_exprt::operandst elements;

0 commit comments

Comments
 (0)