Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of BigInteger in DiscordBitSet.value #864

Merged
merged 1 commit into from
Sep 2, 2023
Merged

Conversation

lukellmann
Copy link
Member

DiscordBitSet can only represent positive numbers, so the BigInteger used for getting a decimal representation can be constructed using the sign-magnitude representation instead of the two's-complement binary representation.

This fixes two bugs:

  • DiscordBitSets with an empty data array couldn't be converted to a BigInteger because the constructor taking the two's-complement binary representation throws a NumberFormatException if the given array is empty.
    This bug was reported by @Tmpod: https://discord.com/channels/556525343595298817/1147254164469063773

  • DiscordBitSets with a negative Long at the last position in their data array would be misinterpreted as negative numbers in the conversion to BigIntegers because the two's-complement binary representation was used.
    Example where this bug could be observed:

// printed -9223372036854775808, should be 9223372036854775808
println(DiscordBitSet(1L shl 63).value)

DiscordBitSet can only represent positive numbers, so the BigInteger
used for getting a decimal representation can be constructed using the
sign-magnitude representation instead of the two's-complement binary
representation.

This fixes two bugs:

 * DiscordBitSets with an empty data array couldn't be converted to a
   BigInteger because the constructor taking the two's-complement binary
   representation throws a NumberFormatException if the given array is
   empty.
   This bug was reported by @Tmpod:
   https://discord.com/channels/556525343595298817/1147254164469063773

 * DiscordBitSets with a negative Long at the last position in their
   data array would be misinterpreted as negative numbers in the
   conversion to BigIntegers because the two's-complement binary
   representation was used.
   Example where this bug could be observed:
   // printed -9223372036854775808, should be 9223372036854775808
   println(DiscordBitSet(1L shl 63).value)
@lukellmann lukellmann merged commit 6749400 into main Sep 2, 2023
6 checks passed
@lukellmann lukellmann deleted the fix-bitset-value branch September 2, 2023 01:34
@Tmpod
Copy link
Contributor

Tmpod commented Sep 3, 2023

Tested this on my affected project and it's all good now, thank you!

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.

2 participants