From d735d23ffa60348b1a946362b535f55c5b08b1f7 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm <mail@robbertvanderhelm.nl> Date: Wed, 1 Feb 2023 17:36:25 +0100 Subject: [PATCH] Document the use of .saturating_sub(1) --- src/midi.rs | 2 +- src/wrapper/util.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/midi.rs b/src/midi.rs index 219ba324..fcbf176c 100644 --- a/src/midi.rs +++ b/src/midi.rs @@ -39,7 +39,7 @@ pub enum MidiConfig { /// [`Plugin::MIDI_INPUT`][crate::prelude::Plugin::MIDI_INPUT]. Also check out the /// [`util`][crate::util] module for convenient conversion functions. /// -/// All of the timings are sample offsets within the current buffer. Out of bounds timings are +/// All of the timings are sample offsets within the current buffer. Out of bound timings are /// clamped to the current buffer's length. All sample, channel and note numbers are zero-indexed. #[derive(Debug, Clone, Copy, PartialEq)] #[non_exhaustive] diff --git a/src/wrapper/util.rs b/src/wrapper/util.rs index 6e161930..c6c9a79a 100644 --- a/src/wrapper/util.rs +++ b/src/wrapper/util.rs @@ -65,6 +65,7 @@ pub fn strlcpy(dest: &mut [c_char], src: &str) { /// out of bounds. #[inline] pub fn clamp_input_event_timing(timing: u32, total_buffer_len: u32) -> u32 { + // If `total_buffer_len == 0`, then 0 is a valid timing let last_valid_index = total_buffer_len.saturating_sub(1); nih_debug_assert!(