Skip to content

Commit 9b57a36

Browse files
committed
Merge branch 'topic-fix-varptr-crash'
2 parents ddbf49d + e60c04f commit 9b57a36

4 files changed

Lines changed: 31 additions & 0 deletions

File tree

pcbasic/basic/memory/memory.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,10 @@ def varptr_(self, args):
515515
name = arg0
516516
error.throw_if(not name, error.STX)
517517
indices, = args
518+
name = self.complete_name(name)
519+
if indices != []:
520+
# pre-allocate array elements, but not scalars which instead throw IFC if undefined
521+
self.arrays.check_dim(name, indices)
518522
var_ptr = self.varptr(name, indices)
519523
return self.values.new_integer().from_int(var_ptr, unsigned=True)
520524

@@ -524,6 +528,7 @@ def varptr_str_(self, args):
524528
error.throw_if(not name, error.STX)
525529
indices = next(args)
526530
list(args)
531+
name = self.complete_name(name)
527532
if indices != []:
528533
# pre-allocate array elements, but not scalars which instead throw IFC if undefined
529534
self.arrays.check_dim(name, indices)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[pcbasic]
2+
font=default
3+
quit=True
4+
run=TEST.BAS
5+
soft-linefeed=True
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
10 ' test VARPTR and VARPTR$ on undefined variables
2+
20 OPEN "OUTPUT.TXT" FOR OUTPUT AS 1
3+
30 ON ERROR GOTO 1000
4+
100 PRINT#1, VARPTR(A)
5+
110 PRINT#1, VARPTR(B(9))
6+
120 PRINT#1, VARPTR(C(12))
7+
200 PRINT#1, VARPTR$(D)
8+
210 PRINT#1, VARPTR$(E(9))
9+
220 PRINT#1, VARPTR$(F(12))
10+
300 CLOSE
11+
999 END
12+
1000 PRINT#1, "error:" err " in " erl
13+
1010 RESUME NEXT
14+

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
error: 5 in 100
2+
5018
3+
error: 9 in 120
4+
error: 5 in 200
5+

6+
error: 9 in 220
7+


0 commit comments

Comments
 (0)