uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit ba7e8a9fb4210d0c9c8aa9b8e33e32ac11c963a2
parent d8667dca0b03383e6f3f91af4e5acaf281597a87
Author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
Date:   Sat, 25 Dec 2021 23:29:36 +0100

uxn_eval: multiply as two uint32s to avoid UB

Diffstat:
Msrc/uxn.c | 4++--
Msrc/uxn.h | 1+
2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/uxn.c b/src/uxn.c @@ -120,7 +120,7 @@ uxn_eval(Uxn *u, Uint16 vec) /* Arithmetic */ case 0x18: /* ADD */ a = pop(u->src), b = pop(u->src); push(u->src, b + a); break; case 0x19: /* SUB */ a = pop(u->src), b = pop(u->src); push(u->src, b - a); break; - case 0x1a: /* MUL */ a = pop(u->src), b = pop(u->src); push(u->src, b * a); break; + case 0x1a: /* MUL */ a = pop(u->src), b = pop(u->src); push(u->src, (Uint32)b * a); break; case 0x1b: /* DIV */ a = pop(u->src), b = pop(u->src); if(a == 0) { u->src->error = 3; a = 1; } push(u->src, b / a); break; case 0x1c: /* AND */ a = pop(u->src), b = pop(u->src); push(u->src, b & a); break; case 0x1d: /* ORA */ a = pop(u->src), b = pop(u->src); push(u->src, b | a); break; @@ -138,7 +138,7 @@ uxn_eval(Uxn *u, Uint16 vec) int uxn_boot(Uxn *u) { - unsigned int i; + Uint32 i; char *cptr = (char *)u; for(i = 0; i < sizeof(*u); ++i) cptr[i] = 0x00; diff --git a/src/uxn.h b/src/uxn.h @@ -13,6 +13,7 @@ typedef unsigned char Uint8; typedef signed char Sint8; typedef unsigned short Uint16; typedef signed short Sint16; +typedef unsigned int Uint32; #define PAGE_PROGRAM 0x0100