diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-05-12 22:07:34 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-05-12 22:07:34 +0100 |
commit | 73afb2c5bb06365f913a7992a555ae34d74eb946 (patch) | |
tree | b4089e8c558868da9d5aec4a6fabde7df4bc62b3 /tr8as.c | |
parent | a68295151788760d694ef136b00c773973aba772 (diff) | |
download | tr8vm-73afb2c5bb06365f913a7992a555ae34d74eb946.tar.gz tr8vm-73afb2c5bb06365f913a7992a555ae34d74eb946.zip |
Check for overflow
Diffstat (limited to 'tr8as.c')
-rw-r--r-- | tr8as.c | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -719,6 +719,9 @@ static uint8_t parse_db(As *as, char **c) else if (!new_ref(as, word, 0xff, as->addr)) return 0; + if (as->addr + 1 > UINT16_MAX) + return error_l("Memory overflow", &as->loc, "output is more than 65535 bytes"); + as->out[as->addr++] = imm & 0xff; if (as->addr > as->size) as->size = as->addr; @@ -754,6 +757,9 @@ static uint8_t parse_dw(As *as, char **c) && !new_ref(as, word, 0xffff, as->addr)) return 0; + if (as->addr + 2 > UINT16_MAX) + return error_l("Memory overflow", &as->loc, "output is more than 65535 bytes"); + as->out[as->addr++] = imm & 0xff; as->out[as->addr++] = imm >> 8; if (as->addr > as->size) |