karyon icon indicating copy to clipboard operation
karyon copied to clipboard

Unchecked requirements

Open YichiZhang0613 opened this issue 6 months ago • 3 comments

In karyon-master/core/src/event.rs, following comment indicates this function should be panic when size = 0 while it actually will not.

/// If `size` is zero, this function will panic.
    pub fn with_buffer_size(size: usize) -> Arc<EventEmitter<T>> {
        Arc::new(Self {
            listeners: Mutex::new(HashMap::new()),
            listener_buffer_size: size,
        })
    }

In karyon-master/core/src/pubsub.rs, this function has the same issue.

    /// If `size` is zero, this function will panic.
    pub fn with_buffer_size(size: usize) -> Arc<Publisher<T>> {
        Arc::new(Self {
            subs: Mutex::new(HashMap::new()),
            subscription_buffer_size: size,
        })
    }

So I think assert_ne!(size, 0); should be appended for each function.

YichiZhang0613 avatar Jun 28 '25 11:06 YichiZhang0613

Hello @YichiZhang0613

Thanks for mentioning this. I'm actually in the process of moving event.rs to a separate crate. You can check out this PR #28 . I just pushed a patch that adds the zero assertion for that function.

hozan23 avatar Jun 28 '25 18:06 hozan23

Thanks for mentioning this. I'm actually in the process of moving event.rs to a separate crate. You can check out this PR #28 . I just pushed a patch that adds the zero assertion for that function.

OK.

YichiZhang0613 avatar Jun 28 '25 22:06 YichiZhang0613

Hello @YichiZhang0613

Thanks for mentioning this. I'm actually in the process of moving event.rs to a separate crate. You can check out this PR #28 . I just pushed a patch that adds the zero assertion for that function.

Hi, I noticed that assert_ne!(size, 0); was added for with_buffer_size(size: usize) -> Arc<EventEmitter<T>>, but not yet for with_buffer_size in karyon-master/core/src/pubsub.rs yet. I fixed it in #33.

YichiZhang0613 avatar Jul 24 '25 04:07 YichiZhang0613