Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/runtime/compact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,12 @@ void object_compactor::insert_mpz(object * o) {
size_t data_sz = sizeof(mpn_digit) * to_mpz(o)->m_value.m_size;
size_t sz = sizeof(mpz_object) + data_sz;
mpz_object * new_o = (mpz_object *)alloc(sz);
memcpy(new_o, to_mpz(o), sizeof(mpz_object));
// Manually copy the `mpz_object` to ensure `mpz` struct padding is left as
// zero as prepared by `object_compactor::alloc`. `memcpy` would copy the
// padding and lead to non-deterministic outputs.
new_o->m_header = to_mpz(o)->m_header;
new_o->m_value.m_sign = to_mpz(o)->m_value.m_sign;
new_o->m_value.m_size = to_mpz(o)->m_value.m_size;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this only in the #else case? Is it not needed with LEAN_USE_GMP?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LEAN_USE_GMP has no padding byte to worry about

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks. (I was seeing new warnings from the C compiler about that code, but then likely unrelated to this change here. Sorry for the noise)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I just saw those too. Probably we should make the change the compiler is suggesting anyway to the other code path, but I haven't thought carefully about it.

lean_set_non_heap_header((lean_object*)new_o, sz, LeanMPZ, 0);
void * data = reinterpret_cast<char*>(new_o) + sizeof(mpz_object);
memcpy(data, to_mpz(o)->m_value.m_digits, data_sz);
Expand Down
1 change: 1 addition & 0 deletions src/runtime/compact.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class LEAN_EXPORT object_compactor {
void operator()(object * o);
size_t size() const { return static_cast<char*>(m_end) - static_cast<char*>(m_begin); }
void const * data() const { return m_begin; }
// Allocate `sz` bytes of zeroed memory.
void * alloc(size_t sz);
};

Expand Down
Loading