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:
parent
bd35f013f8
commit
10d3b75342
@ -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()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user