You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This lint does not catch #1032 for example. But it catches other places. It is probably a good idea to suggest false negatives like #1032 to clippy to be integrated in this lint.
$ cargo clippy -- -W clippy::string_slice
warning: indexing into a string may panic if the index is within a UTF-8 character
--> src/style/color.rs:237:49
|
237 | ... u8::from_str_radix(&s[1..3], 16),
| ^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#string_slice
= note: requested on the command line with `-W clippy::string-slice`
warning: indexing into a string may panic if the index is within a UTF-8 character
--> src/style/color.rs:238:49
|
238 | ... u8::from_str_radix(&s[3..5], 16),
| ^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#string_slice
warning: indexing into a string may panic if the index is within a UTF-8 character
--> src/style/color.rs:239:49
|
239 | ... u8::from_str_radix(&s[5..7], 16),
| ^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#string_slice
warning: indexing into a string may panic if the index is within a UTF-8 character
--> src/widgets/reflow.rs:338:6
|
338 |&src[start..]
| ^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#string_slice
warning: `ratatui` (lib) generated 4 warnings
Finished dev [unoptimized + debuginfo] target(s) in 6.70s
The text was updated successfully, but these errors were encountered:
Enabling the lint and fixing the places yeah. But also finding cases where this lint is not noticing this bad behavior to report this and improve the lint (for us and everyone else).
Created rust-lang/rust-clippy#12708 for the missing hint on Cow, which ratatui uses heavily. Not sure whether there are other false negatives of the lint.
Problem
Slicing of strings can panic on multi width characters. See for example #1032
Solution
Enable the following lint to find all cases where this might happen (now and in the future).
https://rust-lang.github.io/rust-clippy/master/index.html#string_slice
This lint does not catch #1032 for example. But it catches other places. It is probably a good idea to suggest false negatives like #1032 to clippy to be integrated in this lint.
The text was updated successfully, but these errors were encountered: