Skip to content

Fix Integer.undigits/2 to validate negative out-of-range digits#15160

Merged
josevalim merged 1 commit intoelixir-lang:mainfrom
pnezis:fix-undigits-negative-validation
Mar 9, 2026
Merged

Fix Integer.undigits/2 to validate negative out-of-range digits#15160
josevalim merged 1 commit intoelixir-lang:mainfrom
pnezis:fix-undigits-negative-validation

Conversation

@pnezis
Copy link
Contributor

@pnezis pnezis commented Mar 9, 2026

The validation was asymmetric - it rejected positive digits >= base but silently accepted negative digits <= -base. This fix adds the missing check for negative out-of-range digits.

iex> Integer.undigits([100])
** (ArgumentError) invalid digit 100 in base 10
    (elixir 1.18.4) lib/integer.ex:229: Integer.undigits/3
    iex:9: (file)
iex(9)> Integer.undigits([-100])
-100

The validation was asymmetric - it rejected positive digits >= base
but silently accepted negative digits <= -base. This fix adds the
missing check for negative out-of-range digits.
@josevalim josevalim merged commit 8914dcd into elixir-lang:main Mar 9, 2026
15 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@pnezis pnezis deleted the fix-undigits-negative-validation branch March 11, 2026 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants