Skip to content

ARC/newruntime memory corruption #12899

Closed
@zedeus

Description

@zedeus

I don't know why it happens and slightly changing the input can fix it. It also happens with #12823

import strutils, sequtils, strmisc, sugar

let input = @["KXSC, BGMC => 7 PTHL", "PXFX => LBZJ", "WXRQ, ZSCZD => HLQM"]

type
  Reaction = object
    output: string
    input: seq[string]

let reactions = collect(newSeq):
  for l in input:
    let (i, _, o) = l.partition(" => ")
    Reaction(output: o, input: @(i.split(", ")))

echo reactions
echo reactions

Output:

@[(output: "7 PTHL", input: @["KXSC", "BGMC"]), (output: "LBZJ", input: @["PXFX"]), (output: "HLQM", input: \x00\x00\x00", "\x00\x00\x00\x00"])]
@[(output: "(outpu", input: @["KXSC", "@[\"K"]), (output: "LBZJ", input: @["P[\"P"]), (output: "HLQM", input: \x00\x00\x00", "\x00\x00\x00\x00"])]

Changing the code slightly will trigger a segfault:

@[(output: ("PTHL", 7), input: @[("KXSC", 1), ("BGMC", 1)]), (output: ("LBZJ", 1), input: @[("PXFX", 1)]), (output: ("HLQM", 2), input: @[("WXRQ", 2), ("\x00\x00\x00\x00\x00", 12)])]
Traceback (most recent call last)
/home/zed/.choosenim/toolchains/nim-#devel/lib/system.nim(984) bug
/home/zed/.choosenim/toolchains/nim-#devel/lib/system/alloc.nim(945) dealloc
/home/zed/.choosenim/toolchains/nim-#devel/lib/system/alloc.nim(860) rawDealloc
/home/zed/.choosenim/toolchains/nim-#devel/lib/system/avltree.nim(74) del
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions