Skip to content
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

Strange memory behavior when copying strings from file to array #106

Closed
yipal opened this issue Oct 11, 2019 · 3 comments
Closed

Strange memory behavior when copying strings from file to array #106

yipal opened this issue Oct 11, 2019 · 3 comments
Assignees

Comments

@yipal
Copy link

yipal commented Oct 11, 2019

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

  1. 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!

@yipal
Copy link
Author

yipal commented Oct 11, 2019

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.

@robhagemans
Copy link
Owner

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.

@robhagemans robhagemans self-assigned this Oct 12, 2019
@robhagemans
Copy link
Owner

Fixed on develop branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants