uxn_eval: multiply as two uint32s to avoid UB
This commit is contained in:
parent
d8667dca0b
commit
ba7e8a9fb4
|
@ -120,7 +120,7 @@ uxn_eval(Uxn *u, Uint16 vec)
|
||||||
/* Arithmetic */
|
/* Arithmetic */
|
||||||
case 0x18: /* ADD */ a = pop(u->src), b = pop(u->src); push(u->src, b + a); break;
|
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 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 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 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;
|
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
|
int
|
||||||
uxn_boot(Uxn *u)
|
uxn_boot(Uxn *u)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
Uint32 i;
|
||||||
char *cptr = (char *)u;
|
char *cptr = (char *)u;
|
||||||
for(i = 0; i < sizeof(*u); ++i)
|
for(i = 0; i < sizeof(*u); ++i)
|
||||||
cptr[i] = 0x00;
|
cptr[i] = 0x00;
|
||||||
|
|
|
@ -13,6 +13,7 @@ typedef unsigned char Uint8;
|
||||||
typedef signed char Sint8;
|
typedef signed char Sint8;
|
||||||
typedef unsigned short Uint16;
|
typedef unsigned short Uint16;
|
||||||
typedef signed short Sint16;
|
typedef signed short Sint16;
|
||||||
|
typedef unsigned int Uint32;
|
||||||
|
|
||||||
#define PAGE_PROGRAM 0x0100
|
#define PAGE_PROGRAM 0x0100
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue