[librsvg: 2/14] rsvg_css_parse_opacity(): Remove an allocation



commit 9b11cbb8c25aa5c80e532ff807fa52d7d5c5d8af
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Jan 24 10:45:59 2018 -0600

    rsvg_css_parse_opacity(): Remove an allocation

 rust/src/opacity.rs | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
---
diff --git a/rust/src/opacity.rs b/rust/src/opacity.rs
index 50b3b55..f8d1806 100644
--- a/rust/src/opacity.rs
+++ b/rust/src/opacity.rs
@@ -4,10 +4,9 @@
 use ::cssparser::{Parser, ParserInput, Token};
 use ::libc;
 
+use std::ffi::CStr;
 use std::str::FromStr;
 
-use ::glib::translate::*;
-
 use parsers::ParseError;
 use error::*;
 
@@ -121,15 +120,17 @@ impl Opacity {
 
 #[no_mangle]
 pub extern fn rsvg_css_parse_opacity (string: *const libc::c_char) -> OpacitySpec {
-    let s = unsafe { String::from_glib_none (string) };
+    // we can unwrap because libxml2 already validated this for UTF-8
+    let s = unsafe { CStr::from_ptr(string).to_str().unwrap() };
 
-    OpacitySpec::from (Opacity::from_str (&s))
+    OpacitySpec::from(Opacity::from_str(s))
 }
 
 #[cfg(test)]
 mod tests {
     use super::*;
     use std::str::FromStr;
+    use glib::translate::*;
 
     #[test]
     fn parses_inherit () {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]