You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem
I suspect there is a problem with how string memory is being handled when copying from a random access file to an array. What I observe is that when reading multiple records from a random access file, and copying the values to an array, the array content always equals the last value read from the file. I've included a sample program below.
Steps
Run the following program. I expect the last output line to be "A B", but instead it is "B B"
Program
10 OPEN "R",#1,"foo.dat",10
20 FIELD#1,10 AS W$
30 LSET W$="A"
40 PUT#1,1
50 LSET W$="B"
60 PUT#1,2
70 CLOSE
100 REM Read the file
105 DIM X$(2)
110 OPEN "R",#1,"foo.dat",10
120 FIELD#1,10 AS R$
130 GET#1,1
135 X$(1)=R$
140 PRINT R$
150 GET#1,2
155 X$(2)=R$
160 PRINT R$
170 PRINT X$(1);X$(2)
PC-BASIC version: 2.0.2
Operating system version: Linux
Any thoughts?
Thanks for writing pcbasic by the way!
The text was updated successfully, but these errors were encountered:
This behavior is the same even if I replace the array with two string variables.
I looked for gwbasic documentation, but I could not find a description of how string assignment is supposed to work. I do know that I have an old gwbasic program that seems to assume the strings are copied by value, and not by reference.
Hi, thank you for reporting this and for the sample code. This is indeed a regression in version 2.0.2 - the 1.2 branch produces the correct A B line which is also what GW-BASIC produces.
Looks like the string assignment incorrectly copies the string pointer to the FIELD buffer, where it should copy the string by value.
Bug report
Problem
I suspect there is a problem with how string memory is being handled when copying from a random access file to an array. What I observe is that when reading multiple records from a random access file, and copying the values to an array, the array content always equals the last value read from the file. I've included a sample program below.
Steps
Program
PC-BASIC version: 2.0.2
Operating system version: Linux
Any thoughts?
Thanks for writing pcbasic by the way!
The text was updated successfully, but these errors were encountered: