Fix strict-aliasing warnings reported by dak180.

master
Cyp 2010-12-21 16:11:08 +01:00
parent 4a16961c34
commit 49c0f1cd8b
7 changed files with 54 additions and 53 deletions

View File

@ -27,13 +27,9 @@
#include <string.h>
#ifdef __cplusplus
extern "C"
{
#endif //__cplusplus
static inline void endian_uword(UWORD* p)
{
STATIC_ASSERT(sizeof(*p) == 2);
uint8_t bytes[sizeof(*p)];
memcpy(bytes, p, sizeof(*p));
*p = bytes[1]<<8 | bytes[0];
@ -41,6 +37,7 @@ static inline void endian_uword(UWORD* p)
static inline void endian_sword(SWORD* p)
{
STATIC_ASSERT(sizeof(*p) == 2);
uint8_t bytes[sizeof(*p)];
memcpy(bytes, p, sizeof(*p));
*p = bytes[1]<<8 | bytes[0];
@ -48,6 +45,7 @@ static inline void endian_sword(SWORD* p)
static inline void endian_udword(UDWORD* p)
{
STATIC_ASSERT(sizeof(*p) == 4);
uint8_t bytes[sizeof(*p)];
memcpy(bytes, p, sizeof(*p));
*p = bytes[3]<<24 | bytes[2]<<16 | bytes[1]<<8 | bytes[0];
@ -55,13 +53,19 @@ static inline void endian_udword(UDWORD* p)
static inline void endian_sdword(SDWORD* p)
{
STATIC_ASSERT(sizeof(*p) == 4);
uint8_t bytes[sizeof(*p)];
memcpy(bytes, p, sizeof(*p));
*p = bytes[3]<<24 | bytes[2]<<16 | bytes[1]<<8 | bytes[0];
}
#ifdef __cplusplus
template <typename ENUM>
static inline void endian_enum(ENUM *p)
{
STATIC_ASSERT(sizeof(*p) == 4);
uint8_t bytes[sizeof(*p)];
memcpy(bytes, p, sizeof(*p));
*p = ENUM(bytes[3]<<24 | bytes[2]<<16 | bytes[1]<<8 | bytes[0]);
}
#endif //__cplusplus
#endif // ENDIAN_HACK_H

View File

@ -2858,7 +2858,7 @@ BOOL loadGame(const char *pGameToLoad, BOOL keepObjects, BOOL freeMem, BOOL User
for(pl=0;pl<MAX_PLAYERS;pl++)// ajl. must do for every player to stop multiplay/pc players going gaga.
{
//reverse the structure lists so the Research Facilities are in the same order as when saved
reverseObjectList((BASE_OBJECT**)&apsStructLists[pl]);
reverseObjectList(&apsStructLists[pl]);
}
}
@ -3176,7 +3176,7 @@ BOOL loadGame(const char *pGameToLoad, BOOL keepObjects, BOOL freeMem, BOOL User
for(pl=0;pl<MAX_PLAYERS;pl++) // ajl. must do for every player to stop multiplay/pc players going gaga.
{
//reverse the structure lists so the Research Facilities are in the same order as when saved
reverseObjectList((BASE_OBJECT**)&apsStructLists[pl]);
reverseObjectList(&apsStructLists[pl]);
}
}
@ -3379,43 +3379,43 @@ BOOL loadGame(const char *pGameToLoad, BOOL keepObjects, BOOL freeMem, BOOL User
for(pl=0;pl<MAX_PLAYERS;pl++) // ajl. must do for every player to stop multiplay/pc players going gaga.
{
//reverse the structure lists so the Research Facilities are in the same order as when saved
reverseTemplateList((DROID_TEMPLATE**)&apsDroidTemplates[pl]);
reverseTemplateList(&apsDroidTemplates[pl]);
}
for(pl=0;pl<MAX_PLAYERS;pl++)
{
//reverse the droid lists so selections occur in the same order
reverseObjectList((BASE_OBJECT**)&apsLimboDroids[pl]);
reverseObjectList(&apsLimboDroids[pl]);
}
for(pl=0;pl<MAX_PLAYERS;pl++)
{
//reverse the droid lists so selections occur in the same order
reverseObjectList((BASE_OBJECT**)&apsDroidLists[pl]);
reverseObjectList(&apsDroidLists[pl]);
}
for(pl=0;pl<MAX_PLAYERS;pl++)
{
//reverse the droid lists so selections occur in the same order
reverseObjectList((BASE_OBJECT**)&mission.apsDroidLists[pl]);
reverseObjectList(&mission.apsDroidLists[pl]);
}
for(pl=0;pl<MAX_PLAYERS;pl++)
{
//reverse the struct lists so selections occur in the same order
reverseObjectList((BASE_OBJECT**)&mission.apsStructLists[pl]);
reverseObjectList(&mission.apsStructLists[pl]);
}
for(pl=0;pl<MAX_PLAYERS;pl++)
{
//reverse the droid lists so selections occur in the same order
reverseObjectList((BASE_OBJECT**)&apsFeatureLists[pl]);
reverseObjectList(&apsFeatureLists[pl]);
}
for(pl=0;pl<MAX_PLAYERS;pl++)
{
//reverse the droid lists so selections occur in the same order
reverseObjectList((BASE_OBJECT**)&mission.apsFeatureLists[pl]);
reverseObjectList(&mission.apsFeatureLists[pl]);
}
}
@ -10255,8 +10255,8 @@ BOOL loadSaveMessage36(char *pFileData, UDWORD filesize, UDWORD numMessages, UDW
psSaveMessage = (SAVE_MESSAGE_36 *) pFileData;
/* SAVE_MESSAGE_36 */
endian_sdword((SDWORD*)&psSaveMessage->type); /* FIXME: enum may not be this type! */
endian_sdword((SDWORD*)&psSaveMessage->dataType);
endian_enum(&psSaveMessage->type); /* FIXME: enum may not be this type! */
endian_enum(&psSaveMessage->dataType);
endian_udword(&psSaveMessage->objId);
endian_udword(&psSaveMessage->player);
@ -10481,8 +10481,8 @@ static BOOL writeMessageFile(char *pFileName)
psSaveMessage->read = psMessage->read; //flag to indicate whether message has been read
psSaveMessage->player = psMessage->player; //which player this message belongs to
endian_sdword((SDWORD*)&psSaveMessage->type); /* FIXME: enum may be different type! */
endian_sdword((SDWORD*)&psSaveMessage->dataType);
endian_enum(&psSaveMessage->type); /* FIXME: enum may be different type! */
endian_enum(&psSaveMessage->dataType);
endian_udword(&psSaveMessage->objId);
endian_udword(&psSaveMessage->player);
@ -10572,7 +10572,7 @@ BOOL loadSaveFlagV(char *pFileData, UDWORD filesize, UDWORD numflags, UDWORD ver
psSaveflag = (SAVE_FLAG *) pFileData;
/* SAVE_FLAG */
endian_sdword((SDWORD*) &psSaveflag->type); /* FIXME: enum may not be this type! */
endian_enum(&psSaveflag->type); /* FIXME: enum may not be this type! */
endian_udword(&psSaveflag->frameNumber);
endian_udword(&psSaveflag->screenX);
endian_udword(&psSaveflag->screenY);
@ -10774,7 +10774,7 @@ static BOOL writeFlagFile(char *pFileName)
}
/* SAVE_FLAG */
endian_sdword((SDWORD*)&psSaveflag->type); /* FIXME: enum may be different type! */
endian_enum(&psSaveflag->type); /* FIXME: enum may be different type! */
endian_udword(&psSaveflag->frameNumber);
endian_udword(&psSaveflag->screenX);
endian_udword(&psSaveflag->screenY);
@ -10825,7 +10825,7 @@ static BOOL writeFlagFile(char *pFileName)
}
/* SAVE_FLAG */
endian_sdword((SDWORD*)&psSaveflag->type); /* FIXME: enum may be different type! */
endian_enum(&psSaveflag->type); /* FIXME: enum may be different type! */
endian_udword(&psSaveflag->frameNumber);
endian_udword(&psSaveflag->screenX);
endian_udword(&psSaveflag->screenY);

View File

@ -1111,7 +1111,7 @@ void saveCampaignData(void)
{
/*now that every unit for the selected player has been moved into the
mission list - reverse it and fill the transporter with the first ten units*/
reverseObjectList((BASE_OBJECT**)&mission.apsDroidLists[selectedPlayer]);
reverseObjectList(&mission.apsDroidLists[selectedPlayer]);
//find the *first* transporter
for (psDroid = mission.apsDroidLists[selectedPlayer]; psDroid != NULL;

View File

@ -1468,7 +1468,7 @@ BOOL sendTemplate(DROID_TEMPLATE *pTempl)
NETuint32_t(&pTempl->asWeaps[i]);
}
NETuint32_t((uint32_t*)&pTempl->droidType);
NETenum(&pTempl->droidType);
NETuint32_t(&pTempl->multiPlayerID);
return NETend();
@ -1506,7 +1506,7 @@ BOOL recvTemplate(NETQUEUE queue)
NETuint32_t(&pT->asWeaps[i]);
}
NETuint32_t((uint32_t*)&pT->droidType);
NETenum(&pT->droidType);
NETuint32_t(&pT->multiPlayerID);
NETend();

View File

@ -54,16 +54,12 @@ BOOL objShutdown(void)
the last and the last entry becomes the first!*/
void reverseObjectList(BASE_OBJECT **ppsList)
{
BASE_OBJECT *psPrev, *psNext, *psCurrent, *psObjList;
//initialise the pointers
psObjList = *ppsList;
psPrev = psNext = NULL;
psCurrent = psObjList;
BASE_OBJECT *psPrev = NULL;
BASE_OBJECT *psCurrent = *ppsList;
while (psCurrent != NULL)
{
psNext = psCurrent->psNext;
BASE_OBJECT *psNext = psCurrent->psNext;
psCurrent->psNext = psPrev;
psPrev = psCurrent;
psCurrent = psNext;

View File

@ -35,11 +35,6 @@
#include "function.h"
#include "stats.h"
#ifdef __cplusplus
extern "C"
{
#endif //__cplusplus
/* Initialise the object system */
extern BOOL objInitialise(void);
@ -48,13 +43,17 @@ extern BOOL objShutdown(void);
/*goes thru' the list passed in reversing the order so the first entry becomes
the last and the last entry becomes the first!*/
extern void reverseObjectList(BASE_OBJECT **ppsList);
void reverseObjectList(BASE_OBJECT **ppsList);
template <typename OBJECT>
void reverseObjectList(OBJECT **ppsList)
{
BASE_OBJECT *baseList;
reverseObjectList(&baseList);
*ppsList = static_cast<OBJECT *>(baseList);
}
/** Output an informative string about this object. For debugging. */
const char *objInfo(const BASE_OBJECT *psObj);
#ifdef __cplusplus
}
#endif //__cplusplus
#endif // __INCLUDED_SRC_OBJECTS_H__

View File

@ -1318,13 +1318,15 @@ BOOL scrValDefLoad(SDWORD version, INTERP_VAL *psVal, char *pBuffer, UDWORD size
if (psVal->v.oval == NULL)
{
if (!grpCreate((DROID_GROUP**)&(psVal->v.oval)))
DROID_GROUP *tmp = (DROID_GROUP *)psVal->v.oval;
if (!grpCreate(&tmp))
{
debug( LOG_FATAL, "scrValDefLoad: out of memory" );
abort();
break;
}
grpJoin((DROID_GROUP*)(psVal->v.oval), NULL);
grpJoin(tmp, NULL);
psVal->v.oval = tmp;
}
pPos = pBuffer;