[nga-c] now truncate input tokens from files where the token is bigger than the TIB. Ensure the token is null terminated if truncated.

FossilOrigin-Name: b8175efce9504446dadb958daf9d8f16a53c95d54fa01f35e3b6566f34919f92
This commit is contained in:
crc 2024-08-06 13:32:00 +00:00
parent 5b5609688c
commit 5a2867cbb9
5 changed files with 947 additions and 935 deletions

View file

@ -55,6 +55,8 @@
- now report "<none>" for `script:name` if no file is being
run
- now report 0 for `script:arguments` if not running a program
- source read from a file now truncates (w/null termination)
input tokens bigger than the defined text input buffer
Future Notes

View file

@ -852,8 +852,12 @@ variables.
:s:next (-)
&Current v:inc
@Current @TempStrings eq? [ #0 !Current ] if ;
:truncate (s-s)
dup s:length @TempStringMax n:dec gt?
[ #0 over @TempStringMax + store ] if ;
---reveal---
:s:temp (s-s) dup s:length n:inc s:pointer swap copy
:s:temp (s-s) truncate
dup s:length n:inc s:pointer swap copy
s:pointer s:next ;
:s:empty (-s) s:pointer s:next #0 over store ;
}}

BIN
ngaImage

Binary file not shown.

File diff suppressed because it is too large Load diff

View file

@ -31,6 +31,7 @@
#define ACTIVE vm->cpu[vm->active]
#define TIB vm->memory[7]
#define TIB_END vm->memory[8]
#define MAX_DEVICES 32
#define MAX_OPEN_FILES 32
@ -707,6 +708,9 @@ V execute(NgaState *vm, CELL cell) {
V evaluate(NgaState *vm, char *s) {
if (strlen(s) == 0) return;
if (strlen(s) > (TIB_END - TIB)) {
s[TIB_END - TIB] = 0;
}
string_inject(vm, s, TIB);
stack_push(vm, TIB);
execute(vm, vm->interpret);