Negative gamearray access

git-svn-id: https://svn.eduke32.com/eduke32@715 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2008-04-27 06:54:28 +00:00
parent 48dae664b8
commit 9bfd183cec
3 changed files with 56 additions and 38 deletions

View file

@ -1440,24 +1440,21 @@ static void transvartype(int type)
skipcomments(); //skip comments and whitespace skipcomments(); //skip comments and whitespace
if ((*textptr == '[')) //read of array as a gamevar if ((*textptr == '[')) //read of array as a gamevar
{ {
f |= (MAXGAMEVARS<<2);
// initprintf("got an array"); // initprintf("got an array");
textptr++; textptr++;
i=GetADefID(label+(labelcnt<<6)); i=GetADefID(label+(labelcnt<<6));
if (i >= 0) if (i < 0)
{
*scriptptr++=i+1+MAXGAMEVARS;
transvartype(0);
}
else
{ {
error++; error++;
ReportError(ERROR_NOTAGAMEARRAY); ReportError(ERROR_NOTAGAMEARRAY);
return; return;
} }
*scriptptr++=(i|f);
transvartype(0);
skipcomments(); //skip comments and whitespace skipcomments(); //skip comments and whitespace
if (*textptr != ']') if (*textptr != ']')
{ {
error++; error++;
@ -1521,8 +1518,8 @@ static void transvartype(int type)
} }
if (!(error || warning) && g_ScriptDebug > 1) if (!(error || warning) && g_ScriptDebug > 1)
initprintf("%s:%d: debug: accepted gamevar `%s'.\n",compilefile,line_number,label+(labelcnt<<6)); initprintf("%s:%d: debug: accepted gamevar `%s'.\n",compilefile,line_number,label+(labelcnt<<6));
i |= f;
*scriptptr++=i; *scriptptr++=(i|f);
} }
static inline void transvar(void) static inline void transvar(void)

View file

@ -6333,21 +6333,25 @@ static int parse(void)
{ {
if (*insptr==MAXGAMEVARS) // addlogvar for a constant? Har. if (*insptr==MAXGAMEVARS) // addlogvar for a constant? Har.
insptr++; insptr++;
else if (*insptr&(MAXGAMEVARS<<1)) // else if (*insptr > iGameVarCount && (*insptr < (MAXGAMEVARS<<1)+MAXGAMEVARS+1+MAXGAMEARRAYS))
{ else if (*insptr&(MAXGAMEVARS<<2))
m = -1;
lVarID ^= (MAXGAMEVARS<<1);
}
else if (*insptr < MAXGAMEVARS+1+MAXGAMEARRAYS)
{ {
int index; int index;
lVarID ^= (MAXGAMEVARS<<2);
if (lVarID&(MAXGAMEVARS<<1))
{
m = -1;
lVarID ^= (MAXGAMEVARS<<1);
}
insptr++; insptr++;
index=GetGameVarID(*insptr++,g_i,g_p); index=GetGameVarID(*insptr++,g_i,g_p);
if ((index < aGameArrays[lVarID-MAXGAMEVARS-1].size)&&(index>=0)) if ((index < aGameArrays[lVarID].size)&&(index>=0))
{ {
OSD_Printf("CONLOGVAR: L=%d %s[%d] =%d\n",l, aGameArrays[lVarID-MAXGAMEVARS-1].szLabel,index,aGameArrays[lVarID-MAXGAMEVARS-1].plValues[index]); OSD_Printf("CONLOGVAR: L=%d %s[%d] =%d\n",l, aGameArrays[lVarID].szLabel,index,m*aGameArrays[lVarID].plValues[index]);
break; break;
} }
else else
@ -6356,6 +6360,11 @@ static int parse(void)
break; break;
} }
} }
else if (*insptr&(MAXGAMEVARS<<1))
{
m = -1;
lVarID ^= (MAXGAMEVARS<<1);
}
else else
{ {
// invalid varID // invalid varID
@ -7392,10 +7401,10 @@ void execute(int iActor,int iPlayer,int lDist)
return; return;
} }
/* Qbix: Changed variables to be aware of the sizeof *insptr /* Qbix: Changed variables to be aware of the sizeof *insptr
* (wether it is int vs intptr_t), Although it is specificly cast to intptr_t* * (wether it is int vs intptr_t), Although it is specificly cast to intptr_t*
* which might be corrected if the code is converted to use offsets */ * which might be corrected if the code is converted to use offsets */
if (g_t[4]) if (g_t[4])
{ {
g_sp->lotag += TICSPERFRAME; g_sp->lotag += TICSPERFRAME;

View file

@ -532,30 +532,41 @@ int GetGameVarID(int id, int iActor, int iPlayer)
{ {
int inv = 0; int inv = 0;
if (id == MAXGAMEVARS)
{
// OSD_Printf("GetGameVarID(): reading gamevar constant\n");
return(*insptr++);
}
if (id == g_iThisActorID) if (id == g_iThisActorID)
return iActor; return iActor;
if (id<0 || id >= iGameVarCount) if (id<0 || id >= iGameVarCount)
{ {
if (id==MAXGAMEVARS) // if (id < (MAXGAMEVARS<<1)+MAXGAMEVARS+1+MAXGAMEARRAYS)
if (id&(MAXGAMEVARS<<2))
{ {
// OSD_Printf("GetGameVarID(): reading gamevar constant\n"); int index=GetGameVarID(*insptr++,iActor,iPlayer);
return(*insptr++);
} id ^= (MAXGAMEVARS<<2);
if (id < MAXGAMEVARS+1+MAXGAMEARRAYS)
{ if (id&(MAXGAMEVARS<<1)) // negative array access
int index=0;
// OSD_Printf("GetGameVarID(): reading from array\n");
index=GetGameVarID(*insptr++,iActor,iPlayer);
if ((index < aGameArrays[id-MAXGAMEVARS-1].size)&&(index>=0))
inv =aGameArrays[id-MAXGAMEVARS-1].plValues[index];
else
{ {
OSD_Printf("GetGameVarID(): invalid array index (%s[%d])\n",aGameArrays[id-MAXGAMEVARS-1].szLabel,index); id ^= (MAXGAMEVARS<<1);
// OSD_Printf("GetGameVarID(): reading from array\n");
if ((index < aGameArrays[id].size)&&(index>=0))
return(-aGameArrays[id].plValues[index]);
OSD_Printf("GetGameVarID(): invalid array index (%s[%d])\n",aGameArrays[id].szLabel,index);
return -1; return -1;
} }
return(inv);
// OSD_Printf("GetGameVarID(): reading from array\n");
if ((index < aGameArrays[id].size)&&(index>=0))
return(aGameArrays[id].plValues[index]);
OSD_Printf("GetGameVarID(): invalid array index (%s[%d])\n",aGameArrays[id].szLabel,index);
return -1;
} }
if (!(id&(MAXGAMEVARS<<1))) if (!(id&(MAXGAMEVARS<<1)))
{ {
OSD_Printf("GetGameVarID(): invalid gamevar ID (%d)\n",id); OSD_Printf("GetGameVarID(): invalid gamevar ID (%d)\n",id);
@ -701,8 +712,9 @@ int GetGameVar(const char *szGameLabel, int lDefault, int iActor, int iPlayer)
static intptr_t *GetGameValuePtr(const char *szGameLabel) static intptr_t *GetGameValuePtr(const char *szGameLabel)
{ {
int i; int i=0;
for (i=0;i<iGameVarCount;i++)
for (;i<iGameVarCount;i++)
{ {
if (aGameVars[i].szLabel != NULL) if (aGameVars[i].szLabel != NULL)
{ {