Fix gamearrays on 64-bit platforms.

They were broken by r2666, which made their elements intptr_t instead of
int32_t, but this change was not reflected in related allocation code.
WARNING: players on 64-bit platforms should not attempt to load games saved
with r2665 or earlier.

git-svn-id: https://svn.eduke32.com/eduke32@2689 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-05-25 15:23:48 +00:00
parent 7f920c5541
commit 05af53ac4b
3 changed files with 9 additions and 7 deletions

View file

@ -4098,9 +4098,9 @@ nullquote:
if (asize > 0)
{
/*OSD_Printf(OSDTEXT_GREEN "CON_RESIZEARRAY: resizing array %s from %d to %d\n",
aGameArrays[j].szLabel, aGameArrays[j].size, asize / sizeof(int32_t));*/
aGameArrays[j].szLabel, aGameArrays[j].size, asize / GAR_ELTSZ);*/
aGameArrays[j].plValues=Brealloc(aGameArrays[j].plValues, asize);
aGameArrays[j].size = asize / sizeof(int32_t);
aGameArrays[j].size = asize / GAR_ELTSZ;
kread(fil, aGameArrays[j].plValues, asize);
}
@ -4143,7 +4143,7 @@ nullquote:
if (asize > 0)
{
/*OSD_Printf(OSDTEXT_GREEN "CON_RESIZEARRAY: resizing array %s from %d to %d\n", aGameArrays[j].szLabel, aGameArrays[j].size, asize);*/
aGameArrays[j].plValues=Brealloc(aGameArrays[j].plValues, sizeof(int32_t) * asize);
aGameArrays[j].plValues=Brealloc(aGameArrays[j].plValues, GAR_ELTSZ * asize);
aGameArrays[j].size = asize;
}
continue;

View file

@ -158,8 +158,8 @@ int32_t Gv_ReadSave(int32_t fil, int32_t newbehav)
if (kdfread(aGameArrays[i].szLabel,sizeof(uint8_t) * MAXARRAYLABEL, 1, fil) != 1) goto corrupt;
hash_add(&h_arrays, aGameArrays[i].szLabel, i, 1);
aGameArrays[i].plValues=Bcalloc(aGameArrays[i].size,sizeof(int32_t));
if (kdfread(aGameArrays[i].plValues,sizeof(int32_t) * aGameArrays[i].size, 1, fil) < 1) goto corrupt;
aGameArrays[i].plValues=Bcalloc(aGameArrays[i].size, GAR_ELTSZ);
if (kdfread(aGameArrays[i].plValues, GAR_ELTSZ * aGameArrays[i].size, 1, fil) < 1) goto corrupt;
}
// Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
@ -273,7 +273,7 @@ void Gv_WriteSave(FILE *fil, int32_t newbehav)
{
dfwrite(&(aGameArrays[i]),sizeof(gamearray_t),1,fil);
dfwrite(aGameArrays[i].szLabel,sizeof(uint8_t) * MAXARRAYLABEL, 1, fil);
dfwrite(aGameArrays[i].plValues,sizeof(int32_t) * aGameArrays[i].size, 1, fil);
dfwrite(aGameArrays[i].plValues, GAR_ELTSZ * aGameArrays[i].size, 1, fil);
}
G_Util_PtrToIdx(apScriptGameEvent, MAXGAMEEVENTS, script, P2I_FWD_NON0);
@ -417,7 +417,7 @@ int32_t Gv_NewArray(const char *pszLabel, int32_t asize)
aGameArrays[i].szLabel=(char *)Bcalloc(MAXVARLABEL,sizeof(uint8_t));
if (aGameArrays[i].szLabel != pszLabel)
Bstrcpy(aGameArrays[i].szLabel,pszLabel);
aGameArrays[i].plValues=(intptr_t *)Bcalloc(asize,sizeof(int32_t));
aGameArrays[i].plValues=(intptr_t *)Bcalloc(asize,GAR_ELTSZ);
aGameArrays[i].size=asize;
aGameArrays[i].bReset=0;
g_gameArrayCount++;

View file

@ -74,6 +74,8 @@ typedef struct {
} gamearray_t;
#pragma pack(pop)
#define GAR_ELTSZ (sizeof(aGameArrays[0].plValues[0]))
extern gamevar_t aGameVars[MAXGAMEVARS];
extern gamearray_t aGameArrays[MAXGAMEARRAYS];
extern int32_t g_gameVarCount;