Skip to content

Conversation

@czurnieden
Copy link
Contributor

@czurnieden czurnieden commented Jan 15, 2023

Regarding issue #529: do not assume that more than enough memory is automatically allocated and set to 0.

The old code assumes that there is always enough memory allocated to go one further than x.dp[x.used - 1] and
that this memory is set to zero. This can lead to surprises if e.g.: heap is short but not short enough to use tomsfastmath and the developer decides to pepper the code with mp_shrink() to give the OS a chance to reclaim memory. If that is done in s_mp_sub() the assumptions fail and either an out-of-bounds error is caught or memory read with random content which can be zero. Depending on the input. And the compiler.

It is not much, but let's be nice to the future developers.

Cost involved: one mp_digit, its assignment and one branch (a ternary).

This fixes #529

@sjaeckel sjaeckel merged commit 886126c into libtom:develop Mar 31, 2023
@sjaeckel sjaeckel added this to the v2.0.0 milestone Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

should i>=x.used better?

2 participants