fixes #22148; std/memfiles.memSlices nesting now fails with memory sa… (#22154)

* fixes #22148; std/memfiles.memSlices nesting now fails with memory safety capture violation

* adds a test case
This commit is contained in:
ringabout
2023-06-25 23:15:47 +08:00
committed by GitHub
parent 20037a4749
commit 942c378659
2 changed files with 16 additions and 1 deletions

View File

@@ -326,7 +326,7 @@ proc introduceNewLocalVars(c: PTransf, n: PNode): PNode =
return n
of nkProcDef: # todo optimize nosideeffects?
result = newTransNode(n)
let x = freshVar(c, n[namePos].sym)
let x = newSymNode(copySym(n[namePos].sym, c.idgen))
idNodeTablePut(c.transCon.mapping, n[namePos].sym, x)
result[namePos] = x # we have to copy proc definitions for iters
for i in 1..<n.len:

15
tests/iter/t22148.nim Normal file
View File

@@ -0,0 +1,15 @@
discard """
action: compile
"""
import std/memfiles
# bug #22148
proc make*(input: string) =
var inp = memfiles.open(input)
for line in memSlices(inp):
let lineF = MemFile(mem: line.data, size: line.size)
for word in memSlices(lineF, ','):
discard
make("") # Must call to trigger