Closed thareh closed 1 year ago
As written in the commit comment:
"startLine" should never be "<= 0" ...else you will have an OOB again. Also I would suggest to do the check (i < _lines.length) outside of the for loop ...
Something in the lines of this:
Method Join:String(startLine:Int, endLine:Int, s:String)
Local sb:TStringBuffer = New TStringBuffer
'limit range
If startLine <= 0 Then startLine = 1
If endLine >= _lines.Length Then endLine = _lines.Length - 1
For Local i:Int = startLine - 1 To endLine
sb.Append(_lines[i])
sb.Append(s)
Next
Return sb.ToString()
End Method
Generally I am not sure about the "join()" logic:
What happens if you call Join(1,1, someString)
:
For Local i:Int = startLine - 1 To endLine
sb.Append(_lines[i])
sb.Append(s)
Next
becomes:
For Local i:Int = 0 To 1
sb.Append(_lines[i])
sb.Append(s)
Next
Which means it will actually do this:
sb.Append(_lines[0]) ' "line 1" at index 0
sb.Append(s)
sb.Append(_lines[1]) ' "line 2" at index 1
sb.Append(s)
Which in my opinion is not joining "line 1 till line 1" (only line 1) but joining "line 1 till (including) line 2"
The following will cause a crash:
However, adding anything after EndType even just a comment will prevent this.
Environment
bcc -v
: 0.133