Skip to content

Conversation

@bettio
Copy link
Collaborator

@bettio bettio commented Oct 23, 2025

Those bugs were unlikely causing a crash, but still code wasn't correct.
As an additional change: add size_align_up_pow2 and similar utilities to utils.h since they are also required in intn.h as well.

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

@bettio bettio force-pushed the bigint-fixes branch 2 times, most recently from 14c7f13 to 39d06ad Compare October 24, 2025 13:24
make_bigint calls `intn_count_digits` as first step, so if bigres_len
exceeds actual buffer length, `intn_count_digits` reads out-of-bounds.

Signed-off-by: Davide Bettio <davide@uninstall.it>
Make it available project-wide as util function, and rename it for the
sake of clarity.

Signed-off-by: Davide Bettio <davide@uninstall.it>
Function was using num_bytes in SMALL_BIG_EXT case when estimating heap
consumption: the correct input is roughly `num_bytes / sizeof(digit) +
align_padding`.

Also add `intn_required_digits_for_unsigned_integer` for this purpose to
intn.h.

This change required newly introduced `size_align_up_pow2` in utils.h.

Signed-off-by: Davide Bettio <davide@uninstall.it>
Integers length is compared before comparing digits.

Signed-off-by: Davide Bettio <davide@uninstall.it>
Use INTN_DIGIT_BITS instead of `sizeof(intn_digit_t) * 8`.

Signed-off-by: Davide Bettio <davide@uninstall.it>
@bettio bettio merged commit 13a0a46 into atomvm:feature/bigint Oct 25, 2025
183 of 187 checks passed
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.

1 participant