Skip to content

Commit a3067e7

Browse files
committed
Avoid UB by actually initialising git_indexer_progress
1 parent 318bf82 commit a3067e7

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

libgit2-sys/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ pub struct git_checkout_perfdata {
336336
}
337337

338338
#[repr(C)]
339-
#[derive(Copy, Clone)]
339+
#[derive(Copy, Clone, Default)]
340340
pub struct git_indexer_progress {
341341
pub total_objects: c_uint,
342342
pub indexed_objects: c_uint,

src/indexer.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::ffi::CStr;
2-
use std::mem::MaybeUninit;
32
use std::path::Path;
43
use std::{io, marker, mem, ptr};
54

@@ -108,7 +107,7 @@ pub type TransportProgress<'a> = IndexerProgress<'a>;
108107
/// database if, and only if, the pack file is self-contained (i.e. not "thin").
109108
pub struct Indexer<'odb> {
110109
raw: *mut raw::git_indexer,
111-
progress: MaybeUninit<raw::git_indexer_progress>,
110+
progress: raw::git_indexer_progress,
112111
progress_payload_ptr: *mut OdbPackwriterCb<'odb>,
113112
}
114113

@@ -128,7 +127,6 @@ impl<'a> Indexer<'a> {
128127
let odb = odb.map(Binding::raw).unwrap_or_else(ptr::null_mut);
129128

130129
let mut out = ptr::null_mut();
131-
let progress = MaybeUninit::uninit();
132130
let progress_cb: raw::git_indexer_progress_cb = Some(write_pack_progress_cb);
133131
let progress_payload = Box::new(OdbPackwriterCb { cb: None });
134132
let progress_payload_ptr = Box::into_raw(progress_payload);
@@ -148,7 +146,7 @@ impl<'a> Indexer<'a> {
148146

149147
Ok(Self {
150148
raw: out,
151-
progress,
149+
progress: Default::default(),
152150
progress_payload_ptr,
153151
})
154152
}
@@ -161,10 +159,7 @@ impl<'a> Indexer<'a> {
161159
/// `pack-<checksum>.idx` respectively).
162160
pub fn commit(mut self) -> Result<String, Error> {
163161
unsafe {
164-
try_call!(raw::git_indexer_commit(
165-
self.raw,
166-
self.progress.as_mut_ptr()
167-
));
162+
try_call!(raw::git_indexer_commit(self.raw, &mut self.progress));
168163

169164
let name = CStr::from_ptr(raw::git_indexer_name(self.raw));
170165
Ok(name.to_str().expect("pack name not utf8").to_owned())
@@ -191,7 +186,7 @@ impl io::Write for Indexer<'_> {
191186
let ptr = buf.as_ptr() as *mut c_void;
192187
let len = buf.len();
193188

194-
let res = raw::git_indexer_append(self.raw, ptr, len, self.progress.as_mut_ptr());
189+
let res = raw::git_indexer_append(self.raw, ptr, len, &mut self.progress);
195190
if res < 0 {
196191
Err(io::Error::new(
197192
io::ErrorKind::Other,

0 commit comments

Comments
 (0)