Crystal: Invalid memory access (signal 11) at address 0x0

Created on 6 May 2019  路  2Comments  路  Source: crystal-lang/crystal

Extracted from https://github.com/crystal-lang/crystal/issues/7728

https://play.crystal-lang.org/#/r/6u14/edit

abstract struct ColumnBase; end

record ColumnInfo(T, M) < ColumnBase, column_name : String, default : T? = nil, type : T.class = T do
  # Returns the SQL representation for this column.
  def to_column(io : IO) : Nil
  end
end

cols = [
  ColumnInfo(String, Int32).new("name", "Jim"),
  ColumnInfo(Int32, Int32).new("age", 123),
  ColumnInfo(Array(Bool), Int32).new("values", [true, false, false, true, true]),
  ColumnInfo(Int64, Int32).new("id", nil),
]

io = IO::Memory.new

cols.sort_by { |c| true ? -1 : 1 }.each &.to_column io
ColumnInfo(Time, Int32).new("created_at", nil).to_column io
Invalid memory access (signal 11) at address 0x0
[0x55af537d7006] *CallStack::print_backtrace:Int32 +118
[0x55af537c9e90] __crystal_sigfault_handler +192
[0x7f82cf1b93c0] ???
[0x0] ???

Same error against crystal master.

I was able to reduce it a bit, however the stack trace changed a bit.

https://play.crystal-lang.org/#/r/6ujl

abstract struct ColumnBase; end

record ColumnInfo(T) < ColumnBase, column_name : String, default : T? = nil

cols = [
  ColumnInfo(String).new("name"),
  ColumnInfo(Int32).new("age"),
  ColumnInfo(Array(Bool)).new("values"),
  ColumnInfo(Int32).new("id"),
]

io = IO::Memory.new

cols.sort_by { |c| true ? -1 : 1 }.each &.to_s io
ColumnInfo(Time?).new("created_at").to_s io
Invalid memory access (signal 11) at address 0x0
[0x563058616686] *CallStack::print_backtrace:Int32 +118
[0x563058608bc0] __crystal_sigfault_handler +192
[0x7f76ae0be3c0] ???
[0x56305861f926] *Slice(T)::new:read_only<Pointer(UInt8), Int32, Bool>:Slice(UInt8) +22
[0x563058619215] *String#to_slice:Slice(UInt8) +37
[0x56305861ca38] *String#to_s<IO::Memory>:Nil +24
[0x563058662961] *IO::Memory +17
[0x563058668bc0] *ColumnBase+ +32
[0x0] ???
bug topicsemantic

Most helpful comment

I have a fix, I'll send it later today.

All 2 comments

Reduced some more

abstract struct ColumnBase; end

record ColumnInfo(T, M) < ColumnBase, default : T? = nil

cols = [
  ColumnInfo(String, Int32).new("Jim"),
  ColumnInfo(Int32, Int32).new(123),
  ColumnInfo(Array(Bool), Int32).new([true, false, false, true, true]),
]

c = cols.dup

c.each &.to_s

ColumnInfo(Time, Int32).new
Invalid memory access (signal 11) at address 0x0
[0x1065f0b6b] *CallStack::print_backtrace:Int32 +107
[0x1065d5ce5] __crystal_sigfault_handler +181
[0x106653533] sigfault_handler +35
[0x7fff77c5fb3d] _sigtramp +29
[0x1065f3788] *Slice(T)::new:read_only<Pointer(UInt8), Int32, Bool>:Slice(UInt8) +24
[0x1065d6ea9] *String#to_slice:Slice(UInt8) +41
[0x1065d6e49] *String#to_s<String::Builder>:Nil +25
[0x1065f2c68] *String::Builder@IO#<<<String>:String::Builder +24
[0x10663c192] *ColumnBase+@Struct#inspect<String::Builder>:Nil +34

I have a fix, I'll send it later today.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pbrusco picture pbrusco  路  3Comments

asterite picture asterite  路  3Comments

cjgajard picture cjgajard  路  3Comments

Sija picture Sija  路  3Comments

lbguilherme picture lbguilherme  路  3Comments