diff --git a/src/bytes.rs b/src/bytes.rs index 02755fa..03ef45a 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -610,7 +610,8 @@ impl Regex { replacement: &[u8], output: &mut Vec, ) -> Result { - self.code.substitute(subject, replacement, output, 0) + // Safety: options is 0. + unsafe { self.code.substitute(subject, replacement, output, 0) } } /// Replaces all the matches in `subject` with the `replacement`, /// and puts the replaced string in `output`. @@ -633,12 +634,15 @@ impl Regex { replacement: &[u8], output: &mut Vec, ) -> Result { - self.code.substitute( - subject, - replacement, - output, - pcre2_sys::PCRE2_SUBSTITUTE_GLOBAL, - ) + // Safety: PCRE2_SUBSTITUTE_GLOBAL is not a dangerous option. + unsafe { + self.code.substitute( + subject, + replacement, + output, + pcre2_sys::PCRE2_SUBSTITUTE_GLOBAL, + ) + } } } diff --git a/src/ffi.rs b/src/ffi.rs index c2f8f77..0a032b3 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -261,7 +261,9 @@ impl Code { /// Substitute the replacement pattern in subject and put the output in /// output vec. Output vec is will be cleared before use. - pub(crate) fn substitute( + /// Safety: ensure that options field will not cause undefined behavior + /// in pcre2-sys. + pub(crate) unsafe fn substitute( &self, subject: &[u8], replacement: &[u8],