lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <D8JTWL8JY7DM.3IVH6FZ4M49CB@proton.me>
Date: Wed, 19 Mar 2025 00:50:29 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Tamir Duberstein <tamird@...il.com>, Andrew Ballance <andrewjballance@...il.com>
Cc: dakr@...nel.org, airlied@...il.com, simona@...ll.ch, maarten.lankhorst@...ux.intel.com, mripard@...nel.org, tzimmermann@...e.de, corbet@....net, ojeda@...nel.org, alex.gaynor@...il.com, boqun.feng@...il.com, gary@...yguo.net, bjorn3_gh@...tonmail.com, a.hindborg@...nel.org, aliceryhl@...gle.com, tmgross@...ch.edu, acourbot@...dia.com, nouveau@...ts.freedesktop.org, dri-devel@...ts.freedesktop.org, linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org
Subject: Re: [PATCH v2 2/3] rust: alloc: add Vec::resize method

On Tue Mar 18, 2025 at 9:12 PM CET, Tamir Duberstein wrote:
> On Sun, Mar 16, 2025 at 7:17 AM Andrew Ballance
> <andrewjballance@...il.com> wrote:
>> +    pub fn resize(&mut self, new_len: usize, value: T, flags: Flags) -> Result<(), AllocError> {
>> +        if new_len > self.len() {
>> +            self.extend_with(new_len - self.len(), value, flags)
>> +        } else {
>> +            self.truncate(new_len);
>> +            Ok(())
>> +        }
>> +    }
>
> You can avoid underflow checking in debug builds by using `checked_sub`:

`checked_sub` doesn't only avoid underflow in debug builds, but rather
in all builds. But the code below is a good suggestion.

---
Cheers,
Benno

>         match new_len.checked_sub(self.len()) {
>             Some(n) => self.extend_with(n, value, flags),
>             None => {
>                 self.truncate(new_len);
>                 Ok(())
>             }
>         }
>
>>  }
>>
>>  impl<T, A> Drop for Vec<T, A>
>> --
>> 2.48.1
>>
>>
>
> Either way:
>
> Reviewed-by: Tamir Duberstein <tamird@...il.com>



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ