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

64-bit width LogicValues can be incorrect if their integer value is larger than the maximum positive int value in Dart #212

Closed
mkorbel1 opened this issue Dec 1, 2022 · 0 comments · Fixed by #213
Assignees
Labels
bug Something isn't working

Comments

@mkorbel1
Copy link
Contributor

mkorbel1 commented Dec 1, 2022

Describe the bug

Doing things like grabbing a 64-bit slice of a _BigLogicValue or constructing a LogicValue using ofBigInt with width 64 with a value that could be interpreted as a negative signed int can cause clamping behavior in BigInt.toInt(). This causes wrong operation results in a number of cases.

To Reproduce

One example that reproduces the issue (this fails):

      final extraWide = LogicValue.ofBigInt(
        BigInt.parse('f' * 16 + 'f0' * 8, radix: 16),
        128,
      );
      final smaller = extraWide.getRange(0, 64);
      expect(smaller.toInt(), equals(0xf0f0f0f0f0f0f0f0));

Expected behavior

Large 64-bit int values are treated as unsigned during conversions

Actual behavior

Sometimes int values are treated as signed and clamped

Additional: Dart SDK info

No response

Additional: pubspec.yaml

No response

Additional: Context

This type of behavior could occur in a number of places, so it's important to consider everywhere it might occur.

@mkorbel1 mkorbel1 added the bug Something isn't working label Dec 1, 2022
@mkorbel1 mkorbel1 self-assigned this Dec 1, 2022
mkorbel1 added a commit to mkorbel1/rohd that referenced this issue Dec 1, 2022
quekyj pushed a commit to quekyj/rohd that referenced this issue Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant