Skip to content

fix: stack overflow in table.concat function #526

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 4 additions & 5 deletions tablelib.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,18 @@ func tableConcat(L *LState) int {
L.Push(emptyLString)
return 1
}
//TODO should flushing?
retbottom := L.GetTop()
result := ""
for ; i <= j; i++ {
v := tbl.RawGetInt(i)
if !LVCanConvToString(v) {
L.RaiseError("invalid value (%s) at index %d in table for concat", v.Type().String(), i)
}
L.Push(v)
result += LVAsString(v)
if i != j {
L.Push(sep)
result += LVAsString(sep)
}
}
L.Push(stringConcat(L, L.GetTop()-retbottom, L.reg.Top()-1))
L.Push(LString(result))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth considering go lang string builder? https://pkg.go.dev/strings#Builder ?

return 1
}

Expand Down