Skip to content

Conversation

@nhz2
Copy link
Member

@nhz2 nhz2 commented Mar 27, 2024

Fixes #193
This fixes the edge case of calling readbytes! with an empty b but non-zero nb by resizing b initially to 32 bytes if b is too small.

@nhz2 nhz2 marked this pull request as ready for review March 27, 2024 15:45
@nhz2 nhz2 requested a review from mkitti March 27, 2024 15:52
mkitti
mkitti previously approved these changes Mar 27, 2024
@mkitti
Copy link
Member

mkitti commented Mar 27, 2024

Why 32? Should we make it a constant somewhere?

@nhz2
Copy link
Member Author

nhz2 commented Mar 27, 2024

Just a small number, readbytes! is usually called with a 1024 byte buffer in read so this issue usually isn't a problem: https://github.com/JuliaLang/julia/blob/v1.9.4/base/io.jl#L1000

I looked in resize! and if understand this correctly, https://github.com/JuliaLang/julia/blob/4ee10228176c960fc3d0046390ab2ef4df7ab08a/base/array.jl#L1040-L1041 seems to resize to a minimum of 8 bytes so I think I'll change 32 to 8 here as well.

@nhz2 nhz2 merged commit 9d69586 into master Mar 28, 2024
@nhz2 nhz2 deleted the nz/fix-readbytes-loop branch March 28, 2024 00:05
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.

Infinite loop in readbytes!(s, UInt8[], 1)

3 participants