mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2025-01-27 13:53:52 +01:00
Merge pull request #1785 from AsparagusEduardo/pret/pr/malloc
Removed unnecessary malloc.h macros
This commit is contained in:
commit
e74fa7b8c0
@ -2,13 +2,10 @@
|
||||
#define GUARD_ALLOC_H
|
||||
|
||||
#define HEAP_SIZE 0x1C000
|
||||
#define malloc Alloc
|
||||
#define calloc(ct, sz) AllocZeroed((ct) * (sz))
|
||||
#define free Free
|
||||
|
||||
#define FREE_AND_SET_NULL(ptr) \
|
||||
{ \
|
||||
free(ptr); \
|
||||
Free(ptr); \
|
||||
ptr = NULL; \
|
||||
}
|
||||
|
||||
|
@ -1084,7 +1084,7 @@ static u8 GetNextRoomType(void)
|
||||
}
|
||||
|
||||
nextRoomType = roomCandidates[Random() % numRoomCandidates];
|
||||
free(roomCandidates);
|
||||
Free(roomCandidates);
|
||||
if (nextRoomType == PIKE_ROOM_STATUS)
|
||||
TryInflictRandomStatus();
|
||||
|
||||
@ -1363,7 +1363,7 @@ static void SetHintedRoom(void)
|
||||
}
|
||||
|
||||
gSaveBlock2Ptr->frontier.pikeHintedRoomType = roomCandidates[Random() % count];
|
||||
free(roomCandidates);
|
||||
Free(roomCandidates);
|
||||
if (gSaveBlock2Ptr->frontier.pikeHintedRoomType == PIKE_ROOM_STATUS && !AtLeastOneHealthyMon())
|
||||
gSaveBlock2Ptr->frontier.pikeHintedRoomType = PIKE_ROOM_NPC;
|
||||
if (gSaveBlock2Ptr->frontier.pikeHintedRoomType == PIKE_ROOM_DOUBLE_BATTLE && !AtLeastTwoAliveMons())
|
||||
|
@ -1568,7 +1568,7 @@ void GenerateBattlePyramidFloorLayout(u16 *backupMapData, bool8 setPlayerPositio
|
||||
}
|
||||
}
|
||||
RunOnLoadMapScript();
|
||||
free(floorLayoutOffsets);
|
||||
Free(floorLayoutOffsets);
|
||||
}
|
||||
|
||||
void LoadBattlePyramidObjectEventTemplates(void)
|
||||
@ -1697,7 +1697,7 @@ static void SetPyramidObjectPositionsUniformly(u8 objType)
|
||||
} while (!(bits & 4) && TrySetPyramidObjectEventPositionInSquare(objType, floorLayoutOffsets, squareId, objectStartIndex + i));
|
||||
bits &= 1;
|
||||
}
|
||||
free(floorLayoutOffsets);
|
||||
Free(floorLayoutOffsets);
|
||||
}
|
||||
|
||||
static bool8 SetPyramidObjectPositionsInAndNearSquare(u8 objType, u8 squareId)
|
||||
@ -1760,7 +1760,7 @@ static bool8 SetPyramidObjectPositionsInAndNearSquare(u8 objType, u8 squareId)
|
||||
r7 &= 1;
|
||||
}
|
||||
#ifdef BUGFIX
|
||||
free(floorLayoutOffsets);
|
||||
Free(floorLayoutOffsets);
|
||||
#endif
|
||||
|
||||
return (numObjects / 2) > numPlacedObjects;
|
||||
@ -1814,7 +1814,7 @@ static bool8 SetPyramidObjectPositionsNearSquare(u8 objType, u8 squareId)
|
||||
break;
|
||||
}
|
||||
#ifdef BUGFIX
|
||||
free(floorLayoutOffsets);
|
||||
Free(floorLayoutOffsets);
|
||||
#endif
|
||||
|
||||
return (numObjects / 2) > numPlacedObjects;
|
||||
|
@ -1000,7 +1000,7 @@ static void HandleDecorationItemsMenuInput(u8 taskId)
|
||||
DestroyListMenuTask(tMenuTaskId, &sDecorationsScrollOffset, &sDecorationsCursorPos);
|
||||
RemoveDecorationWindow(WINDOW_DECORATION_CATEGORIES);
|
||||
RemoveDecorationItemsOtherWindows();
|
||||
free(sDecorationItemsMenu);
|
||||
Free(sDecorationItemsMenu);
|
||||
sSecretBasePC_SelectedDecorationActions[tDecorationMenuCommand][0](taskId);
|
||||
break;
|
||||
}
|
||||
@ -1161,7 +1161,7 @@ static void DecorationItemsMenuAction_Cancel(u8 taskId)
|
||||
RemoveDecorationItemsScrollIndicators();
|
||||
RemoveDecorationItemsOtherWindows();
|
||||
DestroyListMenuTask(tMenuTaskId, NULL, NULL);
|
||||
free(sDecorationItemsMenu);
|
||||
Free(sDecorationItemsMenu);
|
||||
ReinitDecorationCategoriesWindow(taskId);
|
||||
}
|
||||
|
||||
@ -2060,13 +2060,13 @@ static u8 AddDecorationIconObjectFromIconTable(u16 tilesTag, u16 paletteTag, u8
|
||||
palette.data = GetDecorationIconPicOrPalette(decor, 1);
|
||||
palette.tag = paletteTag;
|
||||
LoadCompressedSpritePalette(&palette);
|
||||
template = malloc(sizeof(struct SpriteTemplate));
|
||||
template = Alloc(sizeof(struct SpriteTemplate));
|
||||
*template = gItemIconSpriteTemplate;
|
||||
template->tileTag = tilesTag;
|
||||
template->paletteTag = paletteTag;
|
||||
spriteId = CreateSprite(template, 0, 0, 0);
|
||||
FreeItemIconTemporaryBuffers();
|
||||
free(template);
|
||||
Free(template);
|
||||
return spriteId;
|
||||
}
|
||||
|
||||
@ -2105,7 +2105,7 @@ static u8 AddDecorationIconObjectFromObjectEvent(u16 tilesTag, u16 paletteTag, u
|
||||
template->tileTag = tilesTag;
|
||||
template->paletteTag = paletteTag;
|
||||
spriteId = CreateSprite(template, 0, 0, 0);
|
||||
free(template);
|
||||
Free(template);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -73,7 +73,7 @@ void CB2_ShowDiploma(void)
|
||||
ResetPaletteFade();
|
||||
FreeAllSpritePalettes();
|
||||
LoadPalette(sDiplomaPalettes, 0, 64);
|
||||
sDiplomaTilemapPtr = malloc(0x1000);
|
||||
sDiplomaTilemapPtr = Alloc(0x1000);
|
||||
InitDiplomaBg();
|
||||
InitDiplomaWindow();
|
||||
ResetTempTileDataBuffers();
|
||||
|
@ -1627,7 +1627,7 @@ static bool8 InitEasyChatScreenStruct(u8 type, u16 *words, u8 displayedPersonTyp
|
||||
u8 templateId;
|
||||
int i;
|
||||
|
||||
sEasyChatScreen = malloc(sizeof(*sEasyChatScreen));
|
||||
sEasyChatScreen = Alloc(sizeof(*sEasyChatScreen));
|
||||
if (sEasyChatScreen == NULL)
|
||||
return FALSE;
|
||||
|
||||
|
@ -1537,13 +1537,13 @@ u8 CreateObjectGraphicsSprite(u16 graphicsId, void (*callback)(struct Sprite *),
|
||||
struct Sprite *sprite;
|
||||
u8 spriteId;
|
||||
|
||||
spriteTemplate = malloc(sizeof(struct SpriteTemplate));
|
||||
spriteTemplate = Alloc(sizeof(struct SpriteTemplate));
|
||||
CopyObjectGraphicsInfoToSpriteTemplate(graphicsId, callback, spriteTemplate, &subspriteTables);
|
||||
if (spriteTemplate->paletteTag != TAG_NONE)
|
||||
LoadObjectEventPalette(spriteTemplate->paletteTag);
|
||||
|
||||
spriteId = CreateSprite(spriteTemplate, x, y, subpriority);
|
||||
free(spriteTemplate);
|
||||
Free(spriteTemplate);
|
||||
|
||||
if (spriteId != MAX_SPRITES && subspriteTables != NULL)
|
||||
{
|
||||
|
@ -92,7 +92,7 @@ static const struct WindowTemplate sFieldRegionMapWindowTemplates[] =
|
||||
void FieldInitRegionMap(MainCallback callback)
|
||||
{
|
||||
SetVBlankCallback(NULL);
|
||||
sFieldRegionMapHandler = malloc(sizeof(*sFieldRegionMapHandler));
|
||||
sFieldRegionMapHandler = Alloc(sizeof(*sFieldRegionMapHandler));
|
||||
sFieldRegionMapHandler->state = 0;
|
||||
sFieldRegionMapHandler->callback = callback;
|
||||
SetMainCallback2(MCB2_InitRegionMapRegisters);
|
||||
|
@ -2271,7 +2271,7 @@ static void Fill1PRecords(struct RankingHall1P *dst, s32 hallFacilityId, s32 lvl
|
||||
{
|
||||
s32 i, j;
|
||||
struct RankingHall1P record1P[HALL_RECORDS_COUNT + 1];
|
||||
struct PlayerHallRecords *playerHallRecords = calloc(1, sizeof(struct PlayerHallRecords));
|
||||
struct PlayerHallRecords *playerHallRecords = AllocZeroed(sizeof(struct PlayerHallRecords));
|
||||
GetPlayerHallRecords(playerHallRecords);
|
||||
|
||||
for (i = 0; i < HALL_RECORDS_COUNT; i++)
|
||||
@ -2298,14 +2298,14 @@ static void Fill1PRecords(struct RankingHall1P *dst, s32 hallFacilityId, s32 lvl
|
||||
record1P[highestId].winStreak = 0;
|
||||
}
|
||||
|
||||
free(playerHallRecords);
|
||||
Free(playerHallRecords);
|
||||
}
|
||||
|
||||
static void Fill2PRecords(struct RankingHall2P *dst, s32 lvlMode)
|
||||
{
|
||||
s32 i, j;
|
||||
struct RankingHall2P record2P[HALL_RECORDS_COUNT + 1];
|
||||
struct PlayerHallRecords *playerHallRecords = calloc(1, sizeof(struct PlayerHallRecords));
|
||||
struct PlayerHallRecords *playerHallRecords = AllocZeroed(sizeof(struct PlayerHallRecords));
|
||||
GetPlayerHallRecords(playerHallRecords);
|
||||
|
||||
for (i = 0; i < HALL_RECORDS_COUNT; i++)
|
||||
@ -2332,7 +2332,7 @@ static void Fill2PRecords(struct RankingHall2P *dst, s32 lvlMode)
|
||||
record2P[highestId].winStreak = 0;
|
||||
}
|
||||
|
||||
free(playerHallRecords);
|
||||
Free(playerHallRecords);
|
||||
}
|
||||
|
||||
static void PrintHallRecords(s32 hallFacilityId, s32 lvlMode)
|
||||
@ -2421,7 +2421,7 @@ void ClearRankingHallRecords(void)
|
||||
void SaveGameFrontier(void)
|
||||
{
|
||||
s32 i;
|
||||
struct Pokemon *monsParty = calloc(PARTY_SIZE, sizeof(struct Pokemon));
|
||||
struct Pokemon *monsParty = AllocZeroed(sizeof(struct Pokemon) * PARTY_SIZE);
|
||||
|
||||
for (i = 0; i < PARTY_SIZE; i++)
|
||||
monsParty[i] = gPlayerParty[i];
|
||||
@ -2436,7 +2436,7 @@ void SaveGameFrontier(void)
|
||||
for (i = 0; i < PARTY_SIZE; i++)
|
||||
gPlayerParty[i] = monsParty[i];
|
||||
|
||||
free(monsParty);
|
||||
Free(monsParty);
|
||||
}
|
||||
|
||||
// Frontier Brain functions.
|
||||
|
@ -1608,7 +1608,7 @@ void CB2_LinkError(void)
|
||||
SetVBlankCallback(VBlankCB_LinkError);
|
||||
ResetBgsAndClearDma3BusyFlags(0);
|
||||
InitBgsFromTemplates(0, sLinkErrorBgTemplates, ARRAY_COUNT(sLinkErrorBgTemplates));
|
||||
sLinkErrorBgTilemapBuffer = tilemapBuffer = malloc(BG_SCREEN_SIZE);
|
||||
sLinkErrorBgTilemapBuffer = tilemapBuffer = Alloc(BG_SCREEN_SIZE);
|
||||
SetBgTilemapBuffer(1, tilemapBuffer);
|
||||
if (InitWindows(sLinkErrorWindowTemplates))
|
||||
{
|
||||
|
@ -913,7 +913,7 @@ void SaveLinkTrainerNames(void)
|
||||
s32 j;
|
||||
s32 nextSpace;
|
||||
s32 connectedTrainerRecordIndices[MAX_RFU_PLAYERS];
|
||||
struct TrainerNameRecord *newRecords = calloc(ARRAY_COUNT(gSaveBlock1Ptr->trainerNameRecords), sizeof(struct TrainerNameRecord));
|
||||
struct TrainerNameRecord *newRecords = AllocZeroed(sizeof(gSaveBlock1Ptr->trainerNameRecords));
|
||||
|
||||
// Check if we already have a record saved for connected trainers.
|
||||
for (i = 0; i < GetLinkPlayerCount(); i++)
|
||||
@ -955,7 +955,7 @@ void SaveLinkTrainerNames(void)
|
||||
|
||||
// Finalize the new list, and clean up.
|
||||
memcpy(gSaveBlock1Ptr->trainerNameRecords, newRecords, sizeof(gSaveBlock1Ptr->trainerNameRecords));
|
||||
free(newRecords);
|
||||
Free(newRecords);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -448,7 +448,7 @@ void ReadMail(struct Mail *mail, void (*exitCallback)(void), bool8 hasText)
|
||||
u16 buffer[2];
|
||||
u16 species;
|
||||
|
||||
sMailRead = calloc(1, sizeof(*sMailRead));
|
||||
sMailRead = AllocZeroed(sizeof(*sMailRead));
|
||||
sMailRead->language = GAME_LANGUAGE;
|
||||
sMailRead->international = TRUE;
|
||||
sMailRead->parserSingle = CopyEasyChatWord;
|
||||
|
@ -315,8 +315,8 @@ static void Task_RecordMixing_Main(u8 taskId)
|
||||
switch (tState)
|
||||
{
|
||||
case 0: // init
|
||||
sSentRecord = malloc(sizeof(*sSentRecord));
|
||||
sReceivedRecords = malloc(sizeof(*sReceivedRecords) * MAX_LINK_PLAYERS);
|
||||
sSentRecord = Alloc(sizeof(*sSentRecord));
|
||||
sReceivedRecords = Alloc(sizeof(*sReceivedRecords) * MAX_LINK_PLAYERS);
|
||||
SetLocalLinkPlayerId(gSpecialVar_0x8005);
|
||||
VarSet(VAR_TEMP_0, 1);
|
||||
sReadyToReceive = FALSE;
|
||||
@ -358,8 +358,8 @@ static void Task_RecordMixing_Main(u8 taskId)
|
||||
case 5: // Wait for the task created by CreateTask_ReestablishCableClubLink
|
||||
if (!gTasks[tLinkTaskId].isActive)
|
||||
{
|
||||
free(sReceivedRecords);
|
||||
free(sSentRecord);
|
||||
Free(sReceivedRecords);
|
||||
Free(sSentRecord);
|
||||
SetLinkWaitingForScript();
|
||||
if (gWirelessCommType != 0)
|
||||
CreateTask(Task_ReturnToFieldRecordMixing, 10);
|
||||
@ -689,7 +689,7 @@ static void ReceiveLilycoveLadyData(LilycoveLady *records, size_t recordSize, u8
|
||||
|
||||
if (GetLilycoveLadyId() == 0)
|
||||
{
|
||||
lilycoveLady = malloc(sizeof(*lilycoveLady));
|
||||
lilycoveLady = Alloc(sizeof(*lilycoveLady));
|
||||
if (lilycoveLady == NULL)
|
||||
return;
|
||||
|
||||
@ -705,7 +705,7 @@ static void ReceiveLilycoveLadyData(LilycoveLady *records, size_t recordSize, u8
|
||||
if (lilycoveLady != NULL)
|
||||
{
|
||||
QuizLadyClearQuestionForRecordMix(lilycoveLady);
|
||||
free(lilycoveLady);
|
||||
Free(lilycoveLady);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -475,8 +475,8 @@ bool32 MoveRecordedBattleToSaveData(void)
|
||||
break;
|
||||
}
|
||||
|
||||
free(battleSave);
|
||||
free(savSection);
|
||||
Free(battleSave);
|
||||
Free(savSection);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1664,7 +1664,7 @@ void CB2_OpenFlyMap(void)
|
||||
SetGpuReg(REG_OFFSET_BG2HOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG3HOFS, 0);
|
||||
SetGpuReg(REG_OFFSET_BG3VOFS, 0);
|
||||
sFlyMap = malloc(sizeof(*sFlyMap));
|
||||
sFlyMap = Alloc(sizeof(*sFlyMap));
|
||||
if (sFlyMap == NULL)
|
||||
{
|
||||
SetMainCallback2(CB2_ReturnToFieldWithOpenMenu);
|
||||
|
@ -921,7 +921,7 @@ static void Task_ShowSecretBaseRegistryMenu(u8 taskId)
|
||||
tSelectedRow = 0;
|
||||
tScrollOffset = 0;
|
||||
ClearDialogWindowAndFrame(0, FALSE);
|
||||
sRegistryMenu = calloc(1, sizeof(*sRegistryMenu));
|
||||
sRegistryMenu = AllocZeroed(sizeof(*sRegistryMenu));
|
||||
tMainWindowId = AddWindow(&sRegistryWindowTemplates[0]);
|
||||
BuildRegistryMenuItems(taskId);
|
||||
FinalizeRegistryMenu(taskId);
|
||||
@ -1006,7 +1006,7 @@ static void HandleRegistryMenuInput(u8 taskId)
|
||||
ClearWindowTilemap(tMainWindowId);
|
||||
RemoveWindow(tMainWindowId);
|
||||
ScheduleBgCopyTilemapToVram(0);
|
||||
free(sRegistryMenu);
|
||||
Free(sRegistryMenu);
|
||||
GoToSecretBasePCRegisterMenu(taskId);
|
||||
break;
|
||||
default:
|
||||
|
12
src/tv.c
12
src/tv.c
@ -3450,7 +3450,7 @@ void ReceiveTvShowsData(void *src, u32 size, u8 playersLinkId)
|
||||
TVShow (*rmBuffer2)[MAX_LINK_PLAYERS][TV_SHOWS_COUNT];
|
||||
TVShow (*rmBuffer)[MAX_LINK_PLAYERS][TV_SHOWS_COUNT];
|
||||
|
||||
rmBuffer2 = malloc(MAX_LINK_PLAYERS * TV_SHOWS_COUNT * sizeof(TVShow));
|
||||
rmBuffer2 = Alloc(MAX_LINK_PLAYERS * TV_SHOWS_COUNT * sizeof(TVShow));
|
||||
if (rmBuffer2 != NULL)
|
||||
{
|
||||
for (i = 0; i < MAX_LINK_PLAYERS; i++)
|
||||
@ -3488,7 +3488,7 @@ void ReceiveTvShowsData(void *src, u32 size, u8 playersLinkId)
|
||||
CompactTVShowArray(gSaveBlock1Ptr->tvShows);
|
||||
DeactivateShowsWithUnseenSpecies();
|
||||
DeactivateGameCompleteShowsIfNotUnlocked();
|
||||
free(rmBuffer2);
|
||||
Free(rmBuffer2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3835,7 +3835,7 @@ void ReceivePokeNewsData(void *src, u32 size, u8 playersLinkId)
|
||||
PokeNews (*rmBuffer2)[MAX_LINK_PLAYERS][POKE_NEWS_COUNT];
|
||||
PokeNews (*rmBuffer)[MAX_LINK_PLAYERS][POKE_NEWS_COUNT];
|
||||
|
||||
rmBuffer2 = malloc(MAX_LINK_PLAYERS * POKE_NEWS_COUNT * sizeof(PokeNews));
|
||||
rmBuffer2 = Alloc(MAX_LINK_PLAYERS * POKE_NEWS_COUNT * sizeof(PokeNews));
|
||||
if (rmBuffer2 != NULL)
|
||||
{
|
||||
for (i = 0; i < MAX_LINK_PLAYERS; i++)
|
||||
@ -3861,7 +3861,7 @@ void ReceivePokeNewsData(void *src, u32 size, u8 playersLinkId)
|
||||
}
|
||||
ClearInvalidPokeNews();
|
||||
ClearPokeNewsIfGameNotComplete();
|
||||
free(rmBuffer2);
|
||||
Free(rmBuffer2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3966,7 +3966,7 @@ static void TranslateShowNames(TVShow *show, u32 language)
|
||||
int i;
|
||||
TVShow **shows;
|
||||
|
||||
shows = calloc(11, sizeof(TVShow *));
|
||||
shows = AllocZeroed(sizeof(TVShow *) * 11);
|
||||
for (i = 0; i < LAST_TVSHOW_IDX; i++)
|
||||
{
|
||||
switch (show[i].common.kind)
|
||||
@ -4023,7 +4023,7 @@ static void TranslateShowNames(TVShow *show, u32 language)
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(shows);
|
||||
Free(shows);
|
||||
}
|
||||
|
||||
void SanitizeTVShowsForRuby(TVShow *shows)
|
||||
|
@ -3365,12 +3365,12 @@ static void Task_InitUnionRoom(u8 taskId)
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
free(data->spawnPlayer);
|
||||
free(data->playerList);
|
||||
free(data->incomingParentList);
|
||||
free(data->incomingChildList);
|
||||
Free(data->spawnPlayer);
|
||||
Free(data->playerList);
|
||||
Free(data->incomingParentList);
|
||||
Free(data->incomingChildList);
|
||||
DestroyTask(data->searchTaskId);
|
||||
free(sWirelessLinkMain.uRoom);
|
||||
Free(sWirelessLinkMain.uRoom);
|
||||
LinkRfu_Shutdown();
|
||||
DestroyTask(taskId);
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user