util::color::space::Space: fix possible segfault with .name()

av_get_colorspace_name could return NULL.

Also, switch from av_get_colorspace_name (frame.c) to
av_color_space_name (pixdesc.c), which is more comprehensive.
This commit is contained in:
Zhiming Wang 2018-09-14 21:25:50 -04:00
parent bd35f013f8
commit 10d3b75342
No known key found for this signature in database
GPG Key ID: 5B58F95EC95965D8

View File

@ -26,9 +26,14 @@ pub enum Space {
}
impl Space {
pub fn name(&self) -> &'static str {
pub fn name(&self) -> Option<&'static str> {
unsafe {
from_utf8_unchecked(CStr::from_ptr(av_get_colorspace_name((*self).into())).to_bytes())
let ptr = av_color_space_name((*self).into());
if ptr.is_null() {
None
} else {
Some(from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()))
}
}
}
}