summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2023-06-25 23:15:47 +0800
committerGitHub <noreply@github.com>2023-06-25 17:15:47 +0200
commit942c37865976e1535855e9206860d7db1c18b2a0 (patch)
tree90ae2cad4eeecc9a8e0989b39c476770318b7799
parent20037a47499ea183afb0e8d2a3f68c2b2952aa5d (diff)
downloadNim-942c37865976e1535855e9206860d7db1c18b2a0.tar.gz
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
-rw-r--r--compiler/transf.nim2
-rw-r--r--tests/iter/t22148.nim15
2 files changed, 16 insertions, 1 deletions
diff --git a/compiler/transf.nim b/compiler/transf.nim
index 0a28fd1a0..6ff1da899 100644
--- a/compiler/transf.nim
+++ b/compiler/transf.nim
@@ -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:
diff --git a/tests/iter/t22148.nim b/tests/iter/t22148.nim
new file mode 100644
index 000000000..9954eed87
--- /dev/null
+++ b/tests/iter/t22148.nim
@@ -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