File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -66,6 +66,9 @@ members = [
6666unexpected_cfgs = { level = " warn" , check-cfg = [' cfg(has_error_description_deprecated)' ] }
6767missing_docs = " deny"
6868
69+ [workspace .lints .clippy ]
70+ undocumented_unsafe_blocks = " deny"
71+
6972[lib ]
7073name = " tectonic"
7174crate-type = [" rlib" ]
Original file line number Diff line number Diff line change @@ -221,9 +221,13 @@ impl EngineAbortedError {
221221 }
222222 }
223223
224- unsafe fn new_with_details ( ) -> Self {
225- let ptr = _ttbc_get_error_message ( ) ;
226- let message = CStr :: from_ptr ( ptr) . to_string_lossy ( ) . into_owned ( ) ;
224+ fn new_with_details ( ) -> Self {
225+ // SAFETY: This is always safe to call
226+ let ptr = unsafe { _ttbc_get_error_message ( ) } ;
227+ // SAFETY: The pointer returned above will always have a null-terminated C-string in it
228+ let message = unsafe { CStr :: from_ptr ( ptr) }
229+ . to_string_lossy ( )
230+ . into_owned ( ) ;
227231 EngineAbortedError { message }
228232 }
229233}
@@ -312,7 +316,7 @@ impl<'a> CoreBridgeLauncher<'a> {
312316
313317 if let Err ( ref e) = result {
314318 if e. downcast_ref :: < EngineAbortedError > ( ) . is_some ( ) {
315- return Err ( unsafe { EngineAbortedError :: new_with_details ( ) } . into ( ) ) ;
319+ return Err ( EngineAbortedError :: new_with_details ( ) . into ( ) ) ;
316320 }
317321 }
318322
Original file line number Diff line number Diff line change @@ -154,7 +154,7 @@ pub unsafe extern "C" fn tectonic_flate_new_decompressor(
154154 done : false ,
155155 } ;
156156
157- Box :: leak ( Box :: new ( dc) ) as * mut Decompressor as * mut _
157+ Box :: into_raw ( Box :: new ( dc) ) . cast :: < libc :: c_void > ( )
158158}
159159
160160/// Decompress some DEFLATEd data.
@@ -175,7 +175,7 @@ pub unsafe extern "C" fn tectonic_flate_decompress_chunk(
175175 output_ptr : * mut u8 ,
176176 output_len : * mut u64 ,
177177) -> libc:: c_int {
178- let mut dc = Box :: from_raw ( handle as * mut Decompressor ) ;
178+ let mut dc = Box :: from_raw ( handle. cast :: < Decompressor > ( ) ) ;
179179 let output = slice:: from_raw_parts_mut ( output_ptr, * output_len as usize ) ;
180180
181181 let ( amount, flag) = match dc. decompress_chunk ( output) {
@@ -195,6 +195,6 @@ pub unsafe extern "C" fn tectonic_flate_decompress_chunk(
195195/// This is a C API function, so it is unsafe.
196196#[ no_mangle]
197197pub unsafe extern "C" fn tectonic_flate_free_decompressor ( handle : * mut libc:: c_void ) {
198- let _dc = Box :: from_raw ( handle as * mut Decompressor ) ;
198+ let _dc = Box :: from_raw ( handle. cast :: < Decompressor > ( ) ) ;
199199 // The box will be freed as we exit.
200200}
Original file line number Diff line number Diff line change @@ -129,6 +129,8 @@ impl XdvipdfmxEngine {
129129 let cpdf = CString :: new ( pdf) ?;
130130
131131 launcher. with_global_lock ( |state| {
132+ // SAFETY: This is called while the global lock is held, and with valid C-strings for
133+ // dvi and pdf.
132134 let r = unsafe {
133135 c_api:: tt_engine_xdvipdfmx_main ( state, & config, cdvi. as_ptr ( ) , cpdf. as_ptr ( ) )
134136 } ;
Original file line number Diff line number Diff line change @@ -189,6 +189,7 @@ impl TexEngine {
189189 // Note that we have to do all of this setup while holding the
190190 // lock, because we're modifying static state variables.
191191
192+ // SAFETY: All methods are called with valid C-strings and while the global lock is held.
192193 let r = unsafe {
193194 use c_api:: * ;
194195 tt_xetex_set_int_variable (
Original file line number Diff line number Diff line change @@ -400,11 +400,8 @@ impl<T: XdvEvents> XdvParser<T> {
400400 // already-read bytes so that the parser gets a nice
401401 // contiguous set of bytes to look at. The copy may involve
402402 // overlapping memory regions (imagine we read 4096 bytes but
403- // only consume 1) so we have to get unsafe.
404- let ptr = buf. as_mut_ptr ( ) ;
405- unsafe {
406- std:: ptr:: copy ( ptr. add ( n_consumed) , ptr, n_saved_bytes) ;
407- }
403+ // only consume 1).
404+ buf. copy_within ( n_consumed..n_in_buffer, 0 ) ;
408405 }
409406
410407 if n_in_buffer != 0 && n_consumed == 0 {
You can’t perform that action at this time.
0 commit comments