Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 241e629

Browse files
Fix Remote::list() when the list is empty
Fixes #1217
1 parent f7648de commit 241e629

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/remote.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,18 @@ impl<'repo> Remote<'repo> {
384384
mem::size_of::<RemoteHead<'_>>(),
385385
mem::size_of::<*const raw::git_remote_head>()
386386
);
387+
if base.is_null() {
388+
// We cannot use slice::from_raw_parts() since that requires
389+
// that the pointer be non-null, but that is fine since the size
390+
// should be zero
391+
if size != 0 {
392+
return Err(Error::from_str(&format!(
393+
"git_remote_ls() set a null pointer for a list of size {}",
394+
size
395+
)));
396+
}
397+
return Ok(&[]);
398+
}
387399
let slice = slice::from_raw_parts(base as *const _, size as usize);
388400
Ok(mem::transmute::<
389401
&[*const raw::git_remote_head],

0 commit comments

Comments
 (0)