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

Bug fix for BytesType.bytes32PaddedLength #2083

Closed
wants to merge 1 commit into from

Conversation

junsung-cho
Copy link
Contributor

@junsung-cho junsung-cho commented Jul 25, 2024

What does this PR do?

Bug fix for BytesType.bytes32PaddedLength

Where should the reviewer start?

#2080

Why is it needed?

BytesType.bytes32PaddedLength() returns incorrect value for lengths greater than 32 and multiples of 32.

BytesType::bytes32PaddedLength‎

    @Override
    public int bytes32PaddedLength() {
        return value.length <= 32
                ? MAX_BYTE_LENGTH
                : (value.length / MAX_BYTE_LENGTH + 1) * MAX_BYTE_LENGTH;
    }

In case of the value.length is 64, 96, 128, ...
It should return 64, 96, 128, ...
However, the results are 96, 128, 160, ...

The corrected code is as follows:

    @Override
    public int bytes32PaddedLength() {
        if (value.length < MAX_BYTE_LENGTH) {
            return MAX_BYTE_LENGTH;
        } else if (value.length % MAX_BYTE_LENGTH == 0) {
            return value.length;
        } else {
            return (value.length / MAX_BYTE_LENGTH + 1) * MAX_BYTE_LENGTH;
        }
    }

Checklist

  • I've read the contribution guidelines.
  • I've added tests (if applicable).
  • I've added a changelog entry if necessary.

fix #2080

@gtebrean
Copy link
Contributor

gtebrean commented Aug 8, 2024

changes will be merged with #2089 because this was created from main branch

@gtebrean gtebrean closed this Aug 8, 2024
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.

BytesType.bytes32PaddedLength() returns incorrect value for lengths greater than 32 and multiples of 32
2 participants