Skip to content

Commit f1ae9fe

Browse files
committed
Implement @tautschnig's fixes
1 parent 59169be commit f1ae9fe

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/analyses/goto_rw.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ void rw_range_sett::add(
475475
entry->second=util_make_unique<range_domaint>();
476476

477477
static_cast<range_domaint&>(*entry->second).push_back(
478-
std::make_pair(range_start, range_end));
478+
{range_start, range_end});
479479
}
480480

481481
void rw_range_sett::get_objects_rec(
@@ -678,7 +678,7 @@ void rw_guarded_range_set_value_sett::add(
678678
entry->second=util_make_unique<guarded_range_domaint>();
679679

680680
static_cast<guarded_range_domaint&>(*entry->second).insert(
681-
std::make_pair(range_start, std::make_pair(range_end, guard.as_expr())));
681+
{range_start, {range_end, guard.as_expr()}});
682682
}
683683

684684
void goto_rw(goto_programt::const_targett target,

src/analyses/goto_rw.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class rw_range_sett
109109

110110
const range_domaint &get_ranges(objectst::const_iterator it) const
111111
{
112-
assert(dynamic_cast<range_domaint*>(it->second.get()));
112+
PRECONDITION(dynamic_cast<range_domaint*>(it->second.get())!=nullptr);
113113
return static_cast<const range_domaint &>(*it->second);
114114
}
115115

@@ -278,7 +278,8 @@ class rw_guarded_range_set_value_sett:public rw_range_set_value_sett
278278

279279
const guarded_range_domaint &get_ranges(objectst::const_iterator it) const
280280
{
281-
assert(dynamic_cast<guarded_range_domaint*>(it->second.get())!=nullptr);
281+
PRECONDITION(
282+
dynamic_cast<guarded_range_domaint*>(it->second.get())!=nullptr);
282283
return static_cast<const guarded_range_domaint &>(*it->second);
283284
}
284285

src/util/freer.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ Author: Reuben Thomas, [email protected]
1212
#include <cstdlib>
1313
#include <utility>
1414

15+
/// A functor wrapping `std::free`. Can be used as the deleter of a unique_ptr
16+
/// to free memory originally allocated by `std::malloc`. This is primarily
17+
/// useful for interfacing with C APIs in a memory-safe way.
18+
/// Note that the approach of using an empty functor as a unique_ptr deleter
19+
/// does not impose any space overhead on the unique_ptr instance, whereas
20+
/// using a function-pointer as the deleter requires the unique_ptr to store
21+
/// this function pointer internally, effectively doubling the size of the
22+
/// object. Therefore, `std::unique_ptr<T, freert>` should be preferred to
23+
/// `std::unique_ptr<T, decltype(&std::free)>`.
1524
struct freert
1625
{
1726
template <typename T>

0 commit comments

Comments
 (0)