Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #23223; prevents insert self-assignment #23225

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2520,6 +2520,8 @@ when hasAlloc or defined(nimscript):
## var a = "abc"
## a.insert("zz", 0) # a <- "zzabc"
## ```
if item.len == 0: # prevents self-assignment
return
var xl = x.len
setLen(x, xl+item.len)
var j = xl-1
Expand Down
7 changes: 7 additions & 0 deletions tests/system/tsystem_misc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,10 @@ block:
doAssert not compiles(echo p.rawProc.repr)
doAssert not compiles(echo p.rawEnv.repr)
doAssert not compiles(echo p.finished)

proc bug23223 = # bug #23223
var stuff = "hello"
stuff.insert ""
doAssert stuff == "hello"

bug23223()
Loading