Skip to content

Commit 770bc63

Browse files
authored
Merge pull request #1614 from evoskuil/master
Be consistent with INPLACE usage, use ceilinged_add, comments, style.
2 parents e953fa5 + 22ac35f commit 770bc63

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

include/bitcoin/system/allocator.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ class allocator
136136
/// -----------------------------------------------------------------------
137137
/// These neither allocate nor deallocate.
138138

139-
// Clang is not yet C++20 compliant in terms of aggregate initialization.
140-
// See [reviews.llvm.org/D140327] for details, resolved in future releases.
141139
template <class Type, class ...Args>
142140
void construct(Type* ptr, Args&&... arguments) THROWS
143141
{

include/bitcoin/system/chain/witness.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,11 @@ class BC_API witness
131131
BC_PUSH_WARNING(SMART_PTR_NOT_NEEDED)
132132
BC_PUSH_WARNING(NO_VALUE_OR_CONST_REF_SHARED_PTR)
133133
static size_t serialized_size(const chunk_cptrs& stack) NOEXCEPT;
134-
static inline size_t element_size(size_t total,
135-
const chunk_cptr& element) NOEXCEPT
134+
static inline size_t element_size(const chunk_cptr& element) NOEXCEPT
136135
{
137136
// Each witness is prefixed with number of elements (bip144).
138137
const auto size = element->size();
139-
return total + variable_size(size) + size;
138+
return ceilinged_add(variable_size(size), size);
140139
};
141140
BC_POP_WARNING()
142141
BC_POP_WARNING()

src/chain/operation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ void operation::assign_data(reader& source) NOEXCEPT
236236
source.set_position(start);
237237

238238
// An invalid source.read_bytes_raw returns nullptr.
239-
data_.reset(POINTER(data_chunk, allocator, source.read_bytes_raw()));
239+
INPLACE(&data_, data_chunk, allocator, source.read_bytes_raw());
240240
}
241241

242242
// All byte vectors are deserializable, stream indicates own failure.

src/chain/witness.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ void witness::assign_data(reader& source, bool prefix) NOEXCEPT
183183
break;
184184

185185
stack_.emplace_back(POINTER(data_chunk, allocator, bytes));
186-
size_ = element_size(size_, stack_.back());
186+
size_ = ceilinged_add(size_, element_size(stack_.back()));
187187
}
188188
}
189189
else
@@ -197,7 +197,7 @@ void witness::assign_data(reader& source, bool prefix) NOEXCEPT
197197
break;
198198

199199
stack_.emplace_back(POINTER(data_chunk, allocator, bytes));
200-
size_ = element_size(size_, stack_.back());
200+
size_ = ceilinged_add(size_, element_size(stack_.back()));
201201
}
202202
}
203203

@@ -300,15 +300,19 @@ const chunk_cptrs& witness::stack() const NOEXCEPT
300300
// static/private
301301
size_t witness::serialized_size(const chunk_cptrs& stack) NOEXCEPT
302302
{
303-
return std::accumulate(stack.begin(), stack.end(), zero, element_size);
303+
return std::accumulate(stack.begin(), stack.end(), zero,
304+
[](size_t total, const chunk_cptr& element) NOEXCEPT
305+
{
306+
return ceilinged_add(total, element_size(element));
307+
});
304308
}
305309

306310
size_t witness::serialized_size(bool prefix) const NOEXCEPT
307311
{
308312
// Witness prefix is an element count, not byte length (unlike script).
309313
// An empty stack is not a valid witnessed tx (no inputs) but a consistent
310314
// serialization is used independently by database so zero stack allowed.
311-
return prefix ? ceilinged_add(size_, variable_size(stack_.size())) : size_;
315+
return prefix ? ceilinged_add(variable_size(stack_.size()), size_) : size_;
312316
}
313317

314318
// Utilities.

0 commit comments

Comments
 (0)