Skip to content

Fix assume_init incorect usage#22

Open
kuznetsss wants to merge 1 commit intodoy:mainfrom
kuznetsss:Fix_assume_init_usage
Open

Fix assume_init incorect usage#22
kuznetsss wants to merge 1 commit intodoy:mainfrom
kuznetsss:Fix_assume_init_usage

Conversation

@kuznetsss
Copy link
Copy Markdown

@kuznetsss kuznetsss commented Feb 14, 2026

Hi, thank you for this crate! It is a really good example how to create pty and spawn a command with it.
While implementing a similar thing in my project I've found a bug in assume_init() usage.
Currently some part of the buffer may be marked as initialised, while it was not actually used.
The implementation of assume_init() is:

    #[inline]
    pub unsafe fn assume_init(&mut self, n: usize) {
        let new = self.filled + n;
        if new > self.initialized {
            self.initialized = new;
        }
    }

Which means that it already counts previously filled bytes, so we don't need to provide prev_filled.

I removed prev_filled and added a test reproducing the bug.

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 this pull request may close these issues.

1 participant