Skip to content

Stack overflow when writing Real that isn't AbstractFloat or Integer #232

@iamed2

Description

@iamed2

Examples:

julia> JSON3.write(3//2)
ERROR: StackOverflowError:
Stacktrace:
     [1] write(::StructTypes.NumberType, buf::Vector{UInt8}, pos::Int64, len::Int64, x::Rational{Int64}; kw::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
       @ JSON3 ~/.julia/packages/JSON3/vguNZ/src/write.jl:213
     [2] write(::StructTypes.NumberType, buf::Vector{UInt8}, pos::Int64, len::Int64, x::Rational{Int64})
       @ JSON3 ~/.julia/packages/JSON3/vguNZ/src/write.jl:213
--- the last 2 lines are repeated 39990 more times ---
 [79983] write(::StructTypes.NumberType, buf::Vector{UInt8}, pos::Int64, len::Int64, x::Rational{Int64}; kw::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
       @ JSON3 ~/.julia/packages/JSON3/vguNZ/src/write.jl:213
julia> using FixedPointDecimals

julia> JSON3.write(FixedDecimal{Int,2}(32.14))
ERROR: StackOverflowError:
Stacktrace:
     [1] write(::StructTypes.NumberType, buf::Vector{UInt8}, pos::Int64, len::Int64, x::FixedDecimal{Int64, 2}; kw::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
       @ JSON3 ~/.julia/packages/JSON3/vguNZ/src/write.jl:213
     [2] write(::StructTypes.NumberType, buf::Vector{UInt8}, pos::Int64, len::Int64, x::FixedDecimal{Int64, 2})
       @ JSON3 ~/.julia/packages/JSON3/vguNZ/src/write.jl:213
--- the last 2 lines are repeated 39990 more times ---
 [79983] write(::StructTypes.NumberType, buf::Vector{UInt8}, pos::Int64, len::Int64, x::FixedDecimal{Int64, 2}; kw::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
       @ JSON3 ~/.julia/packages/JSON3/vguNZ/src/write.jl:213
julia> JSON3.write(π)
ERROR: StackOverflowError:
Stacktrace:
     [1] write(::StructTypes.NumberType, buf::Vector{UInt8}, pos::Int64, len::Int64, x::Irrational{:π}; kw::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
       @ JSON3 ~/.julia/packages/JSON3/vguNZ/src/write.jl:213
     [2] write(::StructTypes.NumberType, buf::Vector{UInt8}, pos::Int64, len::Int64, x::Irrational{:π})
       @ JSON3 ~/.julia/packages/JSON3/vguNZ/src/write.jl:213
--- the last 2 lines are repeated 39990 more times ---
 [79983] write(::StructTypes.NumberType, buf::Vector{UInt8}, pos::Int64, len::Int64, x::Irrational{:π}; kw::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
       @ JSON3 ~/.julia/packages/JSON3/vguNZ/src/write.jl:213

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions