From f053fb84ef2b9673f9e7932f25f37e9944a04bd9 Mon Sep 17 00:00:00 2001 From: Fabian Ebner Date: Thu, 18 Feb 2021 13:47:43 +0100 Subject: [PATCH] array: avoid underflow when array is empty and more is zero serializing an empty array triggered this. Signed-off-by: Fabian Ebner [rustfmt: Wolfgang Bumiller ] Signed-off-by: Wolfgang Bumiller --- perlmod/src/array.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/perlmod/src/array.rs b/perlmod/src/array.rs index ce6e112..895fcdf 100644 --- a/perlmod/src/array.rs +++ b/perlmod/src/array.rs @@ -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);