diff options
| author | The 8472 <git@infinite-source.de> | 2022-11-22 20:54:10 +0100 |
|---|---|---|
| committer | The 8472 <git@infinite-source.de> | 2022-11-22 20:58:43 +0100 |
| commit | d576a9b241a21740226cd32dd0c7da06bf32b46a (patch) | |
| tree | 50a988ef40da729a5ea751f76ae56888b9dd7060 | |
| parent | 66ccf36f161f67b121290e2af2517ead7e695d3b (diff) | |
| download | rust-d576a9b241a21740226cd32dd0c7da06bf32b46a.tar.gz rust-d576a9b241a21740226cd32dd0c7da06bf32b46a.zip | |
add test for issue 104726
| -rw-r--r-- | library/alloc/tests/str.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/library/alloc/tests/str.rs b/library/alloc/tests/str.rs index 9689196ef21..4d182be02c9 100644 --- a/library/alloc/tests/str.rs +++ b/library/alloc/tests/str.rs @@ -1632,6 +1632,18 @@ fn strslice_issue_16878() { } #[test] +fn strslice_issue_104726() { + // Edge-case in the simd_contains impl. + // The first and last byte are the same so it backtracks by one byte + // which aligns with the end of the string. Previously incorrect offset calculations + // lead to out-of-bounds slicing. + #[rustfmt::skip] + let needle = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaba"; + let haystack = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"; + assert!(!haystack.contains(needle)); +} + +#[test] #[cfg_attr(miri, ignore)] // Miri is too slow fn test_strslice_contains() { let x = "There are moments, Jeeves, when one asks oneself, 'Do trousers matter?'"; |
