diff options
author | Kartik Agaram <vc@akkartik.com> | 2019-04-10 17:22:00 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2019-04-10 17:22:00 -0700 |
commit | 52a2a21c1cdefb241aa0e43b9e0b0a027f6dc511 (patch) | |
tree | 6b7c4e48c8442d951e6eaffb2359732a0ed30844 /subx/056trace.subx | |
parent | fdf84d43d1b1e7f2adf246663af2e3daf9600786 (diff) | |
download | mu-52a2a21c1cdefb241aa0e43b9e0b0a027f6dc511.tar.gz |
5074
Fail early when writing to a fake file runs out of space. Makes debugging tests easier. Reads from files, on the other hand, are only buffering to a temporary stream, so it makes sense to silently stop when they run out of space. In the process I uncovered a testing bug in pack.subx: I was missing a trailing space in the expected result, but the test still passed because the space was getting truncated. Being principled about aborting on overflow by default will help avoid such issues.
Diffstat (limited to 'subx/056trace.subx')
-rw-r--r-- | subx/056trace.subx | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/subx/056trace.subx b/subx/056trace.subx index fac2d4e7..cedc512a 100644 --- a/subx/056trace.subx +++ b/subx/056trace.subx @@ -272,7 +272,7 @@ _append-3: # out : address, outend : address, s : (array byte) -> num_bytes_app 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP # . save registers 51/push-ECX - # _append-4(out, outend, &s->data[0], &s->data[s->length]) -> num_bytes_appended/EAX + # EAX = _append-4(out, outend, &s->data[0], &s->data[s->length]) # . . push &s->data[s->length] 8b/copy 1/mod/*+disp8 5/rm32/EBP . . 0/r32/EAX 0x10/disp8 . # copy *(EBP+16) to EAX 8b/copy 0/mod/indirect 0/rm32/EAX . . . 1/r32/ECX . . # copy *EAX to ECX @@ -322,9 +322,9 @@ $_append-4:loop: # if (in >= inend) break 39/compare 3/mod/direct 6/rm32/ESI . . . 1/r32/ECX . . # compare ESI with ECX 7d/jump-if-greater-or-equal $_append-4:end/disp8 - # if (out >= outend) break # for now silently ignore filled up buffer + # if (out >= outend) abort # just to catch test failures fast 39/compare 3/mod/direct 7/rm32/EDI . . . 2/r32/EDX . . # compare EDI with EDX - 7d/jump-if-greater-or-equal $_append-4:end/disp8 + 7d/jump-if-greater-or-equal $_append-4:abort/disp8 # *out = *in 8a/copy-byte 0/mod/indirect 6/rm32/ESI . . . 3/r32/BL . . # copy byte at *ESI to BL 88/copy-byte 0/mod/indirect 7/rm32/EDI . . . 3/r32/BL . . # copy byte at BL to *EDI @@ -347,4 +347,19 @@ $_append-4:end: 5d/pop-to-EBP c3/return +$_append-4:abort: + # . _write(2/stderr, error) + # . . push args + 68/push "stream overflow"/imm32 + 68/push 2/imm32/stderr + # . . call + e8/call _write/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # . syscall(exit, 1) + bb/copy-to-EBX 1/imm32 + b8/copy-to-EAX 1/imm32/exit + cd/syscall 0x80/imm8 + # never gets here + # . . vim:nowrap:textwidth=0 |