Fix image property accessor to copy C string
cargo test passes
This commit is contained in:
parent
19377db422
commit
7bc3f274d2
3 changed files with 8 additions and 6 deletions
|
@ -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.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "magick_rust"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
authors = ["Nathan Fiedler <nathanfiedler@fastmail.fm>"]
|
||||
description = "Selection of Rust bindings for the ImageMagick library."
|
||||
homepage = "https://github.com/nlfiedler/magick-rust"
|
||||
|
|
|
@ -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<String, &'static str> {
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue