# fmt.parseWithSign\(\): prevent edge case overflows · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/5bbacb0c8ce1aa59af5e898e255c544786059d06)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 5bbacb0c8ce1aa59af5e898e255c544786059d06

Requested commit: 5bbacb0c8ce1aa59af5e898e255c544786059d06

Commit: 5bbacb0c8ce1aa59af5e898e255c544786059d06

Tree: adbfde693ae4952daabce2aea03a3c6216acc846

Author: Travis Staloch

Committer: Veikka Tuominen

## Message

```
fmt.parseWithSign(): prevent edge case overflows

previously when T was smaller than 8 bits, it was possible for base
to overflow T (because base is a u8).  this patch prevents this by
accumulating into a U rather than T which is at least 8 bits wide.

this is the best way i could think of to maintain performance.  this
will only affect parsing of integers less than 8 bits by adding one
additional cast at return.  additionally, this patch may be slightly
slower to return an error for integers less than 8 bits which overflow
because it will accumulate a few more digits before the overflow check
at return.

* add tests which previously overflowed when they shouldn't have

closes #18157

```

## Parents

- [a817e27c7d459c8bba4b41931a842158bf3df2d0](https://git.cafe/gitcafe/zig/commit/a817e27c7d459c8bba4b41931a842158bf3df2d0?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/5bbacb0c8ce1aa59af5e898e255c544786059d06?format=markdown)
