diff --git a/include/QF/pr_comp.h b/include/QF/pr_comp.h index b173f0be1..e04e84876 100644 --- a/include/QF/pr_comp.h +++ b/include/QF/pr_comp.h @@ -192,7 +192,7 @@ void PR_Opcode_Init (void); typedef struct statement_s { unsigned short op; - short a,b,c; + unsigned short a,b,c; } dstatement_t; typedef struct diff --git a/libs/gamecode/pr_edict.c b/libs/gamecode/pr_edict.c index 3a785e9e7..b8c101255 100644 --- a/libs/gamecode/pr_edict.c +++ b/libs/gamecode/pr_edict.c @@ -1186,14 +1186,16 @@ PR_LoadProgs (progs_t * pr, const char *progsname) switch (st->op) { case OP_IF: case OP_IFNOT: - if ((unsigned short) st->a >= pr->progs->numglobals - || st->b + i < 0 || st->b + i >= pr->progs->numstatements) + if (st->a >= pr->progs->numglobals + || (short)st->b + i < 0 + || (short)st->b + i >= pr->progs->numstatements) PR_Error (pr, "PR_LoadProgs: out of bounds IF/IFNOT (statement %d)\n", i); break; case OP_GOTO: - if (st->a + i < 0 || st->a + i >= pr->progs->numstatements) + if ((short)st->a + i < 0 + || (short)st->a + i >= pr->progs->numstatements) PR_Error (pr, "PR_LoadProgs: out of bounds GOTO (statement %d)\n", i); @@ -1266,9 +1268,9 @@ PR_LoadProgs (progs_t * pr, const char *progsname) case OP_SHR_F: case OP_SHL_I: case OP_SHR_I: - if ((unsigned short) st->a >= pr->progs->numglobals - || (unsigned short) st->b >= pr->progs->numglobals - || (unsigned short) st->c >= pr->progs->numglobals) + if (st->a >= pr->progs->numglobals + || st->b >= pr->progs->numglobals + || st->c >= pr->progs->numglobals) PR_Error (pr, "PR_LoadProgs: out of bounds global index (statement %d)\n", i); @@ -1279,8 +1281,8 @@ PR_LoadProgs (progs_t * pr, const char *progsname) case OP_NOT_S: case OP_NOT_FNC: case OP_NOT_ENT: - if ((unsigned short) st->a >= pr->progs->numglobals - || (unsigned short) st->c >= pr->progs->numglobals) + if (st->a >= pr->progs->numglobals + || st->c >= pr->progs->numglobals) PR_Error (pr, "PR_LoadProgs: out of bounds global index (statement %d)\n", i); @@ -1301,8 +1303,8 @@ PR_LoadProgs (progs_t * pr, const char *progsname) case OP_STORE_V: case OP_STORE_I: case OP_STOREP_I: - if ((unsigned short) st->a >= pr->progs->numglobals - || (unsigned short) st->b >= pr->progs->numglobals) + if (st->a >= pr->progs->numglobals + || st->b >= pr->progs->numglobals) PR_Error (pr, "PR_LoadProgs: out of bounds global index (statement %d)\n", i); @@ -1319,7 +1321,7 @@ PR_LoadProgs (progs_t * pr, const char *progsname) case OP_CALL8: case OP_DONE: case OP_RETURN: - if ((unsigned short) st->a >= pr->progs->numglobals) + if (st->a >= pr->progs->numglobals) PR_Error (pr, "PR_LoadProgs: out of bounds global index (statement %d)\n", i); diff --git a/libs/gamecode/pr_exec.c b/libs/gamecode/pr_exec.c index 01d135273..b88d114bf 100644 --- a/libs/gamecode/pr_exec.c +++ b/libs/gamecode/pr_exec.c @@ -77,22 +77,21 @@ PR_PrintStatement (progs_t * pr, dstatement_t *s) if (s->op == OP_IF || s->op == OP_IFNOT) Con_Printf ("%sbranch %i (%i)", - PR_GlobalString (pr, (unsigned short) s->a), s->b, + PR_GlobalString (pr, s->a), s->b, addr + s->b); else if (s->op == OP_GOTO) { Con_Printf ("branch %i (%i)", s->a, addr + s->a); } else if ((unsigned int) (s->op - OP_STORE_F) < 6) { - Con_Printf ("%s", PR_GlobalString (pr, (unsigned short) s->a)); + Con_Printf ("%s", PR_GlobalString (pr, s->a)); Con_Printf ("%s", - PR_GlobalStringNoContents (pr, (unsigned short) s->b)); + PR_GlobalStringNoContents (pr, s->b)); } else { if (s->a) - Con_Printf ("%s", PR_GlobalString (pr, (unsigned short) s->a)); + Con_Printf ("%s", PR_GlobalString (pr, s->a)); if (s->b) - Con_Printf ("%s", PR_GlobalString (pr, (unsigned short) s->b)); + Con_Printf ("%s", PR_GlobalString (pr, s->b)); if (s->c) - Con_Printf ("%s", - PR_GlobalStringNoContents (pr, (unsigned short) s->c)); + Con_Printf ("%s", PR_GlobalStringNoContents (pr, s->c)); } Con_Printf ("\n"); } @@ -269,9 +268,9 @@ PR_LeaveFunction (progs_t * pr) The interpretation main loop */ -#define OPA (pr->pr_globals[(unsigned short) st->a]) -#define OPB (pr->pr_globals[(unsigned short) st->b]) -#define OPC (pr->pr_globals[(unsigned short) st->c]) +#define OPA (pr->pr_globals[st->a]) +#define OPB (pr->pr_globals[st->b]) +#define OPC (pr->pr_globals[st->c]) extern cvar_t *pr_boundscheck; @@ -596,14 +595,14 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum) // ================== case OP_IFNOT: if (!OPA.integer_var) - st += st->b - 1; // offset the s++ + st += (short)st->b - 1; // offset the s++ break; case OP_IF: if (OPA.integer_var) - st += st->b - 1; // offset the s++ + st += (short)st->b - 1; // offset the s++ break; case OP_GOTO: - st += st->a - 1; // offset the s++ + st += (short)st->a - 1; // offset the s++ break; case OP_CALL0: case OP_CALL1: