mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-23 00:17:42 +00:00
Do not always zero initialize for rust resize vec
This commit is contained in:
parent
2ac464b186
commit
90dcc1cd30
@ -90,7 +90,7 @@ private:
|
|||||||
rust::Vec<uint8_t> &_data;
|
rust::Vec<uint8_t> &_data;
|
||||||
size_t _pos = 0;
|
size_t _pos = 0;
|
||||||
|
|
||||||
void ensure_size(size_t sz);
|
void ensure_size(size_t sz, bool zero = false);
|
||||||
};
|
};
|
||||||
|
|
||||||
class file_channel : public channel {
|
class file_channel : public channel {
|
||||||
|
@ -66,5 +66,10 @@ fn set_log_level_state_cxx(level: ffi::LogLevelCxx, enabled: bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn resize_vec(vec: &mut Vec<u8>, size: usize) {
|
fn resize_vec(vec: &mut Vec<u8>, size: usize) {
|
||||||
vec.resize(size, 0);
|
if size > vec.len() {
|
||||||
|
vec.reserve(size - vec.len());
|
||||||
|
}
|
||||||
|
unsafe {
|
||||||
|
vec.set_len(size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,15 +209,17 @@ off_t rust_vec_channel::seek(off_t off, int whence) {
|
|||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ensure_size(np);
|
ensure_size(np, true);
|
||||||
_pos = np;
|
_pos = np;
|
||||||
return np;
|
return np;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rust_vec_channel::ensure_size(size_t sz) {
|
void rust_vec_channel::ensure_size(size_t sz, bool zero) {
|
||||||
size_t old_sz = _data.size();
|
size_t old_sz = _data.size();
|
||||||
if (sz > old_sz) {
|
if (sz > old_sz) {
|
||||||
resize_vec(_data, sz);
|
resize_vec(_data, sz);
|
||||||
|
if (zero)
|
||||||
|
memset(_data.data() + old_sz, 0, sz - old_sz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user