Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run tests
run: cargo test
run: |
cargo clippy --all-targets --all-features -- -D warnings
cargo fmt --all -- --check
cargo test

miri:
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -111,7 +114,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Test with ASAN
run: cargo test --tests --target x86_64-unknown-linux-gnu
run: cargo test --tests --target x86_64-unknown-linux-gnu --features asan
env:
RUST_TARGET: x86_64-unknown-linux-gnu
RUST_BACKTRACE: 1
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ path = "examples/escape.rs"

[features]
codspeed = ["criterion2/codspeed"]
asan = [] # for ASAN

[[bench]]
name = "escape"
Expand Down
12 changes: 10 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,16 @@ mod tests {
for i in 0u8..32 {
let s = String::from_utf8(vec![i]).unwrap();
let result = escape(&s);
let expected = serde_json::to_string(&s).unwrap();
assert_eq!(result, expected, "Failed for byte 0x{:02x}", i);
let expected = String::from_utf8(QUOTE_TAB[i as usize].1.to_vec())
.unwrap()
.trim_end_matches('\0')
.to_string();
assert_eq!(
result,
format!("\"{}\"", expected),
"Failed for byte 0x{:02x}",
i
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/simd/avx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ pub unsafe fn format_string(value: &str, dst: &mut [u8]) -> usize {
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd256u::loadu(placeholder[..].as_ptr())
} else {
#[cfg(any(debug_assertions, miri))]
#[cfg(any(debug_assertions, miri, feature = "asan"))]
{
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd256u::loadu(placeholder[..].as_ptr())
Expand Down
2 changes: 1 addition & 1 deletion src/simd/avx512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ pub unsafe fn format_string(value: &str, dst: &mut [u8]) -> usize {
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd512u::loadu(placeholder[..].as_ptr())
} else {
#[cfg(any(debug_assertions, miri))]
#[cfg(any(debug_assertions, miri, feature = "asan"))]
{
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd512u::loadu(placeholder[..].as_ptr())
Expand Down
2 changes: 1 addition & 1 deletion src/simd/neon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub unsafe fn format_string(value: &str, dst: &mut [u8]) -> usize {
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd128u::loadu(placeholder[..].as_ptr())
} else {
#[cfg(any(debug_assertions, miri))]
#[cfg(any(debug_assertions, miri, feature = "asan"))]
{
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd128u::loadu(placeholder[..].as_ptr())
Expand Down
2 changes: 1 addition & 1 deletion src/simd/sse2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ pub unsafe fn format_string(value: &str, dst: &mut [u8]) -> usize {
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd128u::loadu(placeholder[..].as_ptr())
} else {
#[cfg(any(debug_assertions, miri))]
#[cfg(any(debug_assertions, miri, feature = "asan"))]
{
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd128u::loadu(placeholder[..].as_ptr())
Expand Down
2 changes: 1 addition & 1 deletion src/simd/v128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub fn format_string(value: &str, dst: &mut [u8]) -> usize {
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd128u::loadu(placeholder[..].as_ptr())
} else {
#[cfg(any(debug_assertions, miri))]
#[cfg(any(debug_assertions, miri, feature = "asan"))]
{
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd128u::loadu(placeholder[..].as_ptr())
Expand Down