diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f1e97f..34a8943 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [0.3.1] - 2016-01-02 +### Changed +- Fix bug `get_image_property()` to ensure C string is copied. + ## [0.3.0] - 2016-01-02 ### Changed - Add `get_image_property()` function to retrieve, for example, EXIF data. diff --git a/Cargo.toml b/Cargo.toml index e6a522e..8151a66 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "magick_rust" -version = "0.3.0" +version = "0.3.1" authors = ["Nathan Fiedler "] description = "Selection of Rust bindings for the ImageMagick library." homepage = "https://github.com/nlfiedler/magick-rust" diff --git a/src/lib.rs b/src/lib.rs index 44de0a1..9a41161 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -99,7 +99,7 @@ impl MagickWand { } /// Retrieve the named image property value. - pub fn get_image_property(&self, name: &str) -> Result<&str, &'static str> { + pub fn get_image_property(&self, name: &str) -> Result { let c_name = CString::new(name).unwrap(); let result = unsafe { bindings::MagickGetImageProperty(self.wand, c_name.as_ptr()) @@ -107,11 +107,9 @@ impl MagickWand { let value = if result.is_null() { Err("missing property") } else { + // convert (and copy) the C string to a Rust string let cstr = unsafe { CStr::from_ptr(result) }; - match cstr.to_str() { - Ok(v) => Ok(v), - Err(_) => Err("invalid value") - } + Ok(cstr.to_string_lossy().into_owned()) }; unsafe { bindings::MagickRelinquishMemory(result as *mut c_void);