about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-05-04 14:20:16 -0700
committerKartik Agaram <vc@akkartik.com>2019-05-04 14:26:57 -0700
commitc4c30c7dc92ad8f5c00bf8facaa089b4ed9cab53 (patch)
tree8814bb4e7dc13e9a43d7cdba528ceac1317b6a47
parentd2410e14c6af85f917f79de6f19fb6e60d37d74f (diff)
downloadmu-c4c30c7dc92ad8f5c00bf8facaa089b4ed9cab53.tar.gz
5140 - fix an out-of-bounds bug
We were writing 32-bit words when we meant to write 8-bit bytes. Most of
the time this doesn't matter because:
  * x86 is little endian,
  * a write to (x, x+1, x+2, x+3) is over-written by
    the next to   (x+1, x+2, x+3, x+4), and
  * the 3 higher/later bytes are always 0 so no information is lost

The only place this matters is if we're close to the end of the stream.
-rw-r--r--subx/074print-int-decimal.subx4
1 files changed, 2 insertions, 2 deletions
diff --git a/subx/074print-int-decimal.subx b/subx/074print-int-decimal.subx
index a3e2eb9e..b7994c68 100644
--- a/subx/074print-int-decimal.subx
+++ b/subx/074print-int-decimal.subx
@@ -81,8 +81,8 @@ $print-int32-decimal:write-loop:
     8b/copy                         0/mod/indirect  3/rm32/EBX    .           .             .           1/r32/ECX   .               .                 # ECX = *EBX
     # . ECX = &out->data[out->write]
     8d/copy-address                 1/mod/*+disp8   4/rm32/sib    3/base/EBX  1/index/ECX   .           1/r32/ECX   0xc/disp8       .                 # copy EBX+ECX+12 to ECX
-    # . out->data[out->write] = EAX
-    89/copy                         0/mod/indirect  1/rm32/ECX    .           .             .           0/r32/ECX  .                .                 # *ECX = EAX
+    # . out->data[out->write] = AL
+    88/copy-byte                    0/mod/indirect  1/rm32/ECX    .           .             .           0/r32/AL    .               .                 # copy AL to byte at *ECX
     # out->write++
     ff          0/subop/increment   0/mod/indirect  3/rm32/EBX    .           .             .           .           .               .                 # increment *EBX
     eb/jump  $print-int32-decimal:write-loop/disp8