Skip to content

Commit 9f4e149

Browse files
committed
reject unsafe by default
1 parent 271cedc commit 9f4e149

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![deny(unsafe_code)]
12
#![deny(clippy::dbg_macro)]
23

34
#[cfg(not(any(feature = "bat-printer", feature = "syntect-printer")))]

src/ripgrep.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,14 @@ impl<'main> Config<'main> {
348348
fn build_searcher(&self) -> Result<Searcher> {
349349
let mut builder = SearcherBuilder::new();
350350
let mmap = if self.mmap {
351-
unsafe { MmapChoice::auto() }
351+
// Safety: It is not possible to guarantee this configuration is safe on all platforms. However the worst
352+
// case caused by this configuration is SIGBUS (the mapped file is truncated while reading) and it just
353+
// makes hgrep abort.
354+
// See: https://docs.rs/grep-searcher/latest/grep_searcher/struct.MmapChoice.html#method.auto
355+
#[allow(unsafe_code)]
356+
unsafe {
357+
MmapChoice::auto()
358+
}
352359
} else {
353360
MmapChoice::never()
354361
};

0 commit comments

Comments
 (0)