Fix empty names

This commit is contained in:
Zhiming Wang
2021-03-19 15:44:06 +01:00
committed by meh
parent 062606629f
commit a6097fc358
3 changed files with 11 additions and 4 deletions
+9 -1
View File
@@ -39,7 +39,15 @@ impl Codec {
}
pub fn description(&self) -> &str {
unsafe { from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).long_name).to_bytes()) }
unsafe {
let long_name = (*self.as_ptr()).long_name;
if long_name.is_null() {
""
}
else {
from_utf8_unchecked(CStr::from_ptr(long_name).to_bytes())
}
}
}
pub fn medium(&self) -> media::Type {
+1 -2
View File
@@ -2,7 +2,6 @@ use std::{
ffi::CString,
mem,
ops::{Deref, DerefMut},
ptr,
};
use super::{common::Context, destructor};
@@ -199,7 +198,7 @@ pub fn dump(ctx: &Input, index: i32, url: Option<&str>) {
av_dump_format(
ctx.as_ptr() as *mut _,
index,
url.map(|u| u.as_ptr()).unwrap_or(ptr::null()),
url.unwrap_or_else(|| CString::new("").unwrap()).as_ptr(),
0,
);
}
+1 -1
View File
@@ -174,7 +174,7 @@ pub fn dump(ctx: &Output, index: i32, url: Option<&str>) {
av_dump_format(
ctx.as_ptr() as *mut _,
index,
url.map(|u| u.as_ptr()).unwrap_or(ptr::null()),
url.unwrap_or_else(|| CString::new("").unwrap()).as_ptr(),
1,
);
}