Skip to content

Commit

Permalink
Use address sanitizer to check for memory errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zakcutner committed Aug 28, 2020
1 parent 700f13f commit 935d072
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 23 deletions.
43 changes: 37 additions & 6 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,42 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: true
- uses: actions-rs/toolchain@v1
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
components: clippy, rustfmt
default: true
- run: cargo fmt --all -- --check
- run: cargo build --workspace --all-targets --all-features
- run: cargo clippy --workspace --all-targets --all-features -- -D warnings
- run: cargo test --workspace --all-features
- name: Run rustfmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- name: Build all targets
uses: actions-rs/cargo@v1
with:
command: build
args: --workspace --all-targets --all-features
- name: Run Clippy linter
uses: actions-rs/cargo@v1
with:
command: clippy
args: --workspace --all-targets --all-features -- -D warnings
- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
args: --workspace --all-features
- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2020-08-28
override: true
components: rust-src
- name: Run tests with address sanitizer
uses: actions-rs/cargo@v1
env:
ASAN_SYMBOLIZER_PATH: /usr/lib/llvm-9/bin/llvm-symbolizer
RUSTFLAGS: -Zsanitizer=address
RUSTDOCFLAGS: -Zsanitizer=address
with:
command: test
args: --workspace --all-features --target x86_64-unknown-linux-gnu -Zbuild-std
18 changes: 12 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
default: true
- env:
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
- name: Login to registry
uses: actions-rs/cargo@v1
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo login "$CARGO_REGISTRY_TOKEN"
- run: cargo publish
with:
command: login
args: "$CARGO_REGISTRY_TOKEN"
- name: Publish crate
uses: actions-rs/cargo@v1
with:
command: publish
11 changes: 0 additions & 11 deletions tests/i386.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use memmem::{Searcher, TwoWaySearcher};
use std::{
fs::{self, File},
io::{BufRead, BufReader},
Expand All @@ -10,20 +9,10 @@ fn search(haystack: &str, needle: &str) {
let haystack = haystack.as_bytes();
let needle = needle.as_bytes();

let searcher = TwoWaySearcher::new(needle);
assert_eq!(searcher.search_in(haystack).is_some(), result);

assert_eq!(twoway::find_bytes(haystack, needle).is_some(), result);

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
{
use sliceslice::x86::DynamicAvx2Searcher;

assert_eq!(
unsafe { sse4_strstr::avx2_strstr_v2(haystack, needle).is_some() },
result
);

let searcher = unsafe { DynamicAvx2Searcher::new(needle.to_owned().into_boxed_slice()) };
assert_eq!(unsafe { searcher.search_in(haystack) }, result);
}
Expand Down

0 comments on commit 935d072

Please sign in to comment.