bmx-ng / bcc

A next-generation bcc parser for BlitzMax
zlib License
33 stars 13 forks source link

Use of generics can cause crash #593

Closed thareh closed 1 year ago

thareh commented 2 years ago

The following will cause a crash:

Framework BRL.Blitz

Type Foo<T>
EndType

However, adding anything after EndType even just a comment will prevent this.

Environment

GWRon commented 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
GWRon commented 1 year ago

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"