diff options
author | Bilal Elmoussaoui <belmouss@redhat.com> | 2023-02-08 20:02:10 +0100 |
---|---|---|
committer | Bilal Elmoussaoui <belmouss@redhat.com> | 2023-02-08 20:02:10 +0100 |
commit | 9ccc49489664ac56caf6d3f8a01953926c06cea1 (patch) | |
tree | 58ce82a6a859844b6e9a95253d6058fd5fcf798a /gdk-pixbuf-loader | |
parent | 34f2b319bdbb831d60d0ed08b63b746c7bc2294c (diff) | |
download | librsvg-9ccc49489664ac56caf6d3f8a01953926c06cea1.tar.gz |
gdk-pixbuf-loader: Groupunsafe scopes
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/792>
Diffstat (limited to 'gdk-pixbuf-loader')
-rw-r--r-- | gdk-pixbuf-loader/src/lib.rs | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/gdk-pixbuf-loader/src/lib.rs b/gdk-pixbuf-loader/src/lib.rs index c895acbb..63fc6a46 100644 --- a/gdk-pixbuf-loader/src/lib.rs +++ b/gdk-pixbuf-loader/src/lib.rs @@ -268,24 +268,25 @@ mod tests { #[test] fn signature() { let info = pb_format_new(); - - for i in 0..2 { - let ptr = unsafe { info.signature.offset(i) }; - if i == 2 { - assert_eq!(unsafe { (*ptr).prefix }, null_mut()); - continue; - } else { - assert_ne!(unsafe { (*ptr).prefix }, null_mut()); - if unsafe { (*ptr).mask } != null_mut() { - // Mask can be null - assert_eq!( - unsafe { libc::strlen((*ptr).prefix as *mut c_char) }, - unsafe { libc::strlen((*ptr).mask as *mut c_char) } - ); + unsafe { + for i in 0..2 { + let ptr = info.signature.offset(i); + if i == 2 { + assert_eq!((*ptr).prefix, null_mut()); + continue; + } else { + assert_ne!((*ptr).prefix, null_mut()); + if (*ptr).mask != null_mut() { + // Mask can be null + assert_eq!( + libc::strlen((*ptr).prefix as *mut c_char), + libc::strlen((*ptr).mask as *mut c_char) + ); + } + // Relevance must be 0 to 100 + assert!((*ptr).relevance >= 0); + assert!((*ptr).relevance <= 100); } - // Relevance must be 0 to 100 - assert!(unsafe { (*ptr).relevance } >= 0); - assert!(unsafe { (*ptr).relevance } <= 100); } } } @@ -357,15 +358,15 @@ mod tests { 0xff ); } + unsafe { + let ctx = crate::begin_load(None, Some(prep_cb), None, null_mut(), null_mut()); + assert_ne!(ctx, null_mut()); - let ctx = unsafe { crate::begin_load(None, Some(prep_cb), None, null_mut(), null_mut()) }; - assert_ne!(ctx, null_mut()); - - let inc = unsafe { - crate::load_increment(ctx, SVG_DATA.as_ptr(), SVG_DATA.len() as u32, null_mut()) - }; - assert_ne!(inc, 0); + let inc = + crate::load_increment(ctx, SVG_DATA.as_ptr(), SVG_DATA.len() as u32, null_mut()); + assert_ne!(inc, 0); - unsafe { crate::stop_load(ctx, null_mut()) }; + crate::stop_load(ctx, null_mut()); + } } } |