Skip to content

fix: reject integers that do not fit the target type - #366

Open
SashaMIT wants to merge 1 commit into
spf13:masterfrom
SashaMIT:fix/narrow-integer-range
Open

SashaMIT wants to merge 1 commit into
spf13:masterfrom
SashaMIT:fix/narrow-integer-range

Conversation

@SashaMIT

@SashaMIT SashaMIT commented Sep 30, 2026 •

Copy link
Copy Markdown

ToInt8E("128") returned -128 and a nil error. ToInt8E("-129") returned 127. ToUint8E("256") returned 0. ToInt8E(int64(128)) did the same. The string was parsed at the width of int, then cast to the narrower type, which keeps the low bits.

127 and -128 still fit in int8. 8.9 is still 8. 255 still fits in uint8.

Red: -128 and a nil error. Green: go test .

ToInt8E("128") returned -128 and a nil error. The value was parsed at the width of int, then cast, which keeps the low bits.

Signed-off-by: Sasha Mitchell <sash.t.mitchell@gmail.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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