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

uint2str underflows when 1 digit #105

Open
aelmanaa opened this issue Jun 16, 2021 · 0 comments
Open

uint2str underflows when 1 digit #105

aelmanaa opened this issue Jun 16, 2021 · 0 comments

Comments

@aelmanaa
Copy link

aelmanaa commented Jun 16, 2021

bstr[k--] = byte(uint8(48 + _i % 10));

Hi

I have few revert issues when I tried to format 1 digit numbers (1 ,2 ,3..Etc) .

uint k = len - 1; --> length is 1 and k is 0

bstr[k--] = byte(uint8(48 + _i % 10)); underflows as k is unsigned so 0-1 = -1

suggestion to have something like this. "k" starts with 1 and is decremented before operation

        uint k = len ;
        while (_i != 0) {
            bstr[--k] = bytes1(uint8(48 + _i % 10));
            _i /= 10;
        }
        return string(bstr);
@aelmanaa aelmanaa changed the title uint2str overflows when 1 digit uint2str underflows when 1 digit Jun 16, 2021
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