Skip to content

Conversation

@bettio
Copy link
Collaborator

@bettio bettio commented Oct 6, 2025

The following pattern it might return garbage now:

if (term_is_any_integer(t)) {
  x = (uint64_t) term_maybe_unbox_int(t);
}

term_is_any_integer(t) and term_is_boxed_integer(t) are true also for big integers, so in some situations the API might return garbage, since there are no specific APIs.

Introduce new APIs for handling the most common integer types.

Continuation of #1863

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 fix-int-usage branch 2 times, most recently from 138be64 to 2b9e045 Compare October 7, 2025 11:08
bettio added 4 commits October 8, 2025 14:29
Add functions that are specific to int32 and int64 and less error prone.
These functions have been introduced after big integers introduction in
order to avoid bugs (since previous functions were more error prone).

Signed-off-by: Davide Bettio <davide@uninstall.it>
Add a function for converting the uint64_t special case.
Support for int32_t and int64_t was already there, but also uint64_t can
be reppresented using 2 digits.
The newly introduce predicate also counts digits so input doesn't have
to be normalized.

Signed-off-by: Davide Bettio <davide@uninstall.it>
uint32_t and uint64_t are widely common when dealing with low level
features such as peripherals. So, add new functions to avoid possible
bugs with quite common usages.

Signed-off-by: Davide Bettio <davide@uninstall.it>
Functions such as `term_is_any_integer` return true also with big
integers, but `term_maybe_unbox_int` and other similar functions will
return garbage if such a big integer term is used as an argument.
Fix existing code in order to avoid bugs, using newly introduced
`term_is_(u)int32/(u)int64` and `term_to_(u)int32/(u)int64`.

Signed-off-by: Davide Bettio <davide@uninstall.it>
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