fxm wrote: ↑Mar 08, 2024 19:06
I will come back to this code when bugs #1 and #2 are fixed.
I have fixes for bug #1 and #2 which I should be able to push out today.
I started to explore enabling copyback for string*n and zstring*n passed to byref as string. And got side tracked by already existing and unsafe combinations of implicit string conversions that current and older fbc versions allow but can easily lead to a program crash, overwriting past the end of allocated buffers. So I'd like to get an understanding of some issues there before pushing next changes.
For example, just by brute force trying every combination that fbc allows (perhaps as a novice programmer would try), can induce a crash with this:
Code: Select all
sub proc( byref s as wstring )
s = "byref as wstring" '' crash, assignment is longer than temporary
end sub
dim s as string = "value"
proc( s ) '' creates temporary wstring 6 wchars long, incl. zero terminator
But if we ensure that our starting buffer is large enough to handle the assignment, here's the expected changes for VARIABLES if string*n and zstring*n and wstring*n passed to byref as string is allowed to be modified:
Code: Select all
dim s as string
dim f as string * 20
dim z as zstring * 20
dim w as wstring * 20
#macro reset_values
s = "no copyback"
f = "no copyback"
z = "no copyback"
w = "no copyback"
#endmacro
sub p1( byref s as string )
s = "copyback "
end sub
reset_values
'' fbc-1.10.1 fbc-1.20.0
p1( s ): print s '' copyback copyback
p1( f ): print f '' copyback copyback
p1( z ): print z '' no copyback copyback <<<<
p1( w ): print w '' no copyback copyback <<<<
print
sub p2( byref s as zstring )
s = "copyback "
end sub
reset_values
'' fbc-1.10.1 fbc-1.20.0
p2( s ): print s '' copyback copyback
p2( f ): print f '' copyback copyback
p2( z ): print z '' copyback copyback
p2( w ): print w '' no copyback no copyback
print
sub p3( byref s as wstring )
s = "copyback "
end sub
reset_values
'' fbc-1.10.1 fbc-1.20.0
p3( s ): print s '' no copyback no copyback
p3( f ): print f '' no copyback no copyback
p3( z ): print z '' no copyback no copyback
p3( w ): print w '' copyback copyback
print