Skip to content

Commit 10a41c9

Browse files
- free old string before INPUTing the new one, and copy the new one so it gets MALLOCed correctly
1 parent 1879de5 commit 10a41c9

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

doc/TODO

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ Will not be done:
103103

104104
- it would not be difficult to allow any variable to hold a string, but in most dialects that is an error.
105105

106+
- EduSystem 25 BASIC has a weird LINPUT that is just "longer string INPUT", and does not work like LINPUT in BP or others
107+
106108
- STORE and RECALL from Applesoft, which writes and reads all the values in an array to cassette.
107109

108110
- RESTORE* and RESTORE$ from Dartmouth, which reset the numeric vs. string DATA pointers.

src/retrobasic.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2615,8 +2615,11 @@ static void perform_statement(list_t *statement_entry)
26152615
if (*end == ',' || *end == ' ')
26162616
end++;
26172617
} else {
2618+
// get rid of any previous string
2619+
if (value->string)
2620+
free(value->string);
26182621
// our code strips the separator
2619-
value->string = strtostr(end, &end);
2622+
value->string = str_new(strtostr(end, &end));
26202623
num_input++;
26212624
}
26222625

@@ -2715,7 +2718,10 @@ static void perform_statement(list_t *statement_entry)
27152718
if (*end == ',' || *end == ' ')
27162719
end++;
27172720
} else {
2718-
value->string = strtostr(end, &end);
2721+
if (value->string)
2722+
free(value->string);
2723+
// our code strips the separator
2724+
value->string = str_new(strtostr(end, &end));
27192725
num_input++;
27202726
}
27212727

@@ -2821,7 +2827,10 @@ static void perform_statement(list_t *statement_entry)
28212827
if (*end == ',' || *end == ' ')
28222828
end++;
28232829
} else {
2824-
value->string = strtostr(end, &end);
2830+
if (value->string)
2831+
free(value->string);
2832+
// our code strips the separator
2833+
value->string = str_new(strtostr(end, &end));
28252834
num_input++;
28262835
}
28272836
} // go to next variable

0 commit comments

Comments
 (0)