Skip to content

take! after pushfirst! reads garbage values #54097

Closed
@nhz2

Description

@nhz2

Here is a MWE:

julia> b = pushfirst!([0x02], 0x01)
2-element Vector{UInt8}:
 0x01
 0x02

julia> take!(IOBuffer(b))
5-element Vector{UInt8}:
 0x01
 0x02
 0x69
 0x73
 0x69
julia> versioninfo()
Julia Version 1.12.0-DEV.347
Commit c0611e8c49c (2024-04-15 17:22 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × AMD Ryzen 7 7800X3D 8-Core Processor
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, znver4)
Threads: 1 default, 0 interactive, 1 GC (on 16 virtual cores)

I think the issue is

data = copyto!(StringVector(io.size), 1, io.data, io.offset + 1, nbytes)

using StringVector(io.size) instead of StringVector(nbytes).

The pushfirst! causes the IOBuffer to have a nonzero offset field (added in #53192) which makes nbytes and io.size different.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions