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

Change "while (true)" inside Strings.sol #5185

Closed
BullshitLabProducts opened this issue Sep 3, 2024 · 1 comment
Closed

Change "while (true)" inside Strings.sol #5185

BullshitLabProducts opened this issue Sep 3, 2024 · 1 comment

Comments

@BullshitLabProducts
Copy link

BullshitLabProducts commented Sep 3, 2024

🧐 Motivation

@Amxx
Just an Idea, in the contract contracts/utils/Strings.sol there is a function called toString(uint256 value), which ends like:

while (true) {
    ptr--;
    assembly ("memory-safe") {
        mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
    }
    value /= 10;
    if (value == 0) break;
}
return buffer;

My idea is to change the logical condition to:

while (value != 0) {
    ptr--;
    assembly ("memory-safe") {
        mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
    }
    value /= 10;
}
return buffer;

Avoiding using break in loops helps minimize potential logical errors which may occur later on and it's best practice.

📝 Details

Change the logical condition of the while loop inside Strings.sol (please refer to the above)
@BullshitLabProducts
Copy link
Author

Converted to a pull request
Thanks

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

No branches or pull requests

1 participant