array: avoid underflow when array is empty and more is zero

serializing an empty array triggered this.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
[rustfmt: Wolfgang Bumiller <w.bumiller@proxmox.com>]
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Fabian Ebner 2021-02-18 13:47:43 +01:00 committed by Wolfgang Bumiller
parent dc04b1694f
commit f053fb84ef

View File

@ -102,6 +102,9 @@ impl Array {
/// Pre-extend the array to up to the specified length..
pub fn reserve(&self, more: usize) {
if more == 0 {
return;
}
let idx = self.len() + more - 1;
unsafe {
ffi::RSPL_av_extend(self.av(), idx as libc::ssize_t);