rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

`from_str_radix` hex "+" pitfall

Open Rudxain opened this issue 3 weeks ago • 3 comments

Description

This seems like a common mistake. It consists on using code like this:

u8::from_str_radix(hex_slice, 16)

to decode a hexadecimal string into an integer, unintentionally (in most cases) allowing + as a valid prefix for hex sequences. I say "unintentional" because hex-strs typically represent arbitrary data, not numbers/numerals.

[!note] Prev paragraph was edited for clarity

IDK if there's an existing lint-rule where this should be included, or if it warrants a new lint, that's why I've opened a blank issue

Version


Additional Labels

@rustbot label +C-enhancement

Rudxain avatar Dec 10 '25 16:12 Rudxain

Isn't from_str_radix already return a Result?

profetia avatar Dec 10 '25 17:12 profetia

from_str_radix(x, 16) allows strings like +0 which is probably not what people are expecting going by that github search.

Jarcho avatar Dec 10 '25 20:12 Jarcho