Skip to content

Code Comment Inconsistency #548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
YichiZhang0613 opened this issue Feb 9, 2025 · 0 comments · May be fixed by #551
Open

Code Comment Inconsistency #548

YichiZhang0613 opened this issue Feb 9, 2025 · 0 comments · May be fixed by #551

Comments

@YichiZhang0613
Copy link

In web-audio-api-rs-main/src/lib.rs, the comment "panic if the given value is not lower than or equal to zero" means panic if length >0 while the code panics if length <= 0.

/// Assert that the given value number is a valid buffer length, i.e. greater than zero
///
/// # Panics
///
/// This function will panic if:
/// - the given value is not lower than or equal to zero
///
#[track_caller]
#[inline(always)]
pub(crate) fn assert_valid_buffer_length(length: usize) {
    assert!(
        length > 0,
        "NotSupportedError - Invalid length: {:?} is less than or equal to minimum bound (0)",
        length,
    );
}

In web-audio-api-rs-main/src/render/quantum.rs, the comment means panic if index > self.channels.len() which should be index >= self.channels.len()

/// Get the samples from this specific channel.
    ///
    /// # Panics
    /// Panics if the index is greater than the available number of channels
    pub fn channel_data(&self, index: usize) -> &AudioRenderQuantumChannel {
        &self.channels[index]
    }

    /// Get the samples (mutable) from this specific channel.
    ///
    /// # Panics
    /// Panics if the index is greater than the available number of channels
    pub fn channel_data_mut(&mut self, index: usize) -> &mut AudioRenderQuantumChannel {
        &mut self.channels[index]
    }

Same problem in web-audio-api-rs-main/src/buffer.rs, the comment means panic if index > self.channels.len() which should be index >= self.channels.len().

/// Get the samples from this specific channel.
    ///
    /// Panics if the index is greater than the available number of channels
    // @note - this one is used in
    pub(crate) fn channel_data(&self, index: usize) -> &ChannelData {
        &self.channels[index]
    }

    /// Get the samples (mutable) from this specific channel.
    ///
    /// Panics if the index is greater than the available number of channels
    pub(crate) fn channel_data_mut(&mut self, index: usize) -> &mut ChannelData {
        &mut self.channels[index]
    }

So may be the comment should be changed from "Panics if the index is greater than the available number of channels" to "Panics if index >= self.channels.len()".

In web-audio-api-rs-main/src/node/panner.rs, I noticed you modify the question I mentioned before as "RangeError - maxDistance must be strictly positive" but the comment should be also modified.

///
    /// Panics if the provided value is negative.
    pub fn set_max_distance(&mut self, value: f64) {
        assert!(
            value > 0.,
            "RangeError - maxDistance must be strictly positive"
        );

This comment mentions code panic if value is not finite, while the code doesn't check it.

/// This function will panic if:
/// - the given value is not finite and lower than zero
#[track_caller]
#[inline(always)]
#[allow(clippy::manual_range_contains)]
pub(crate) fn assert_valid_cone_outer_gain(value: f64) {
    assert!(
        value >= 0. && value <= 1.,
        "InvalidStateError - coneOuterGain must be in the range [0, 1]"
    );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant