diff --git a/Descent3/BOA.cpp b/Descent3/BOA.cpp index 1fb2dbda..b590bc74 100644 --- a/Descent3/BOA.cpp +++ b/Descent3/BOA.cpp @@ -2243,8 +2243,8 @@ void ComputeAABB(bool f_full) { int n_new; - nfaces = (int16_t *)mem_malloc(sizeof(int16_t) * rp->num_faces); - used = (bool *)mem_malloc(sizeof(bool) * rp->num_faces); + nfaces = mem_rmalloc(rp->num_faces); + used = mem_rmalloc(rp->num_faces); for (count1 = 0; count1 < rp->num_faces; count1++) { used[count1] = false; diff --git a/Descent3/ConfigItem.cpp b/Descent3/ConfigItem.cpp index e7965b16..6e70b117 100644 --- a/Descent3/ConfigItem.cpp +++ b/Descent3/ConfigItem.cpp @@ -672,7 +672,7 @@ void ConfigItem::Add(int count, ...) { m_rbCount = count; m_rbList = (UIRadioButton **)mem_malloc(sizeof(UIRadioButton *) * m_rbCount); m_iNumIDs = count; - m_iID = (int *)mem_malloc(sizeof(int) * m_iNumIDs); + m_iID = mem_rmalloc(m_iNumIDs); // make sure mallocs are ok ASSERT((m_tiList) && (m_rbList) && (m_iID)); // initialize variables @@ -723,7 +723,7 @@ void ConfigItem::Add(int count, ...) { m_sCount = 1; m_sList = (NewUISlider **)mem_malloc(sizeof(NewUISlider *) * 1); m_iNumIDs = 1; - m_iID = (int *)mem_malloc(sizeof(int) * 1); + m_iID = mem_rmalloc(1); // make sure mallocs are ok ASSERT((m_sList) && (m_iID)); // get unique ID @@ -765,7 +765,7 @@ void ConfigItem::Add(int count, ...) { m_tiCount = 2; m_tiList = (UITextItem **)mem_malloc(sizeof(UITextItem *) * 2); m_iNumIDs = 1; - m_iID = (int *)mem_malloc(sizeof(int) * 1); + m_iID = mem_rmalloc(1); // make sure mallocs mallocs are ok ASSERT((m_tiList) && (m_bList) && (m_iID)); // adjust the curr x/y for the button @@ -802,7 +802,7 @@ void ConfigItem::Add(int count, ...) { m_tiCount = count; m_tiList = (UITextItem **)mem_malloc(sizeof(UITextItem *) * m_tiCount); m_iNumIDs = 1; - m_iID = (int *)mem_malloc(sizeof(int) * 1); + m_iID = mem_rmalloc(1); // make sure mallocs ok ASSERT((m_lbList) && (m_tiList) && (m_iID)); // adjust the curr x/y for the listbox @@ -842,7 +842,7 @@ void ConfigItem::Add(int count, ...) { m_tiCount = 2; m_tiList = (UITextItem **)mem_malloc(sizeof(UITextItem *) * 2); m_iNumIDs = 1; - m_iID = (int *)mem_malloc(sizeof(int) * 1); + m_iID = mem_rmalloc(1); // make sure mallocs mallocs are ok ASSERT((m_tiList) && (m_bList) && (m_iID)); // adjust the curr x/y for the button @@ -879,7 +879,7 @@ void ConfigItem::Add(int count, ...) { m_tiCount = 4; m_tiList = (UITextItem **)mem_malloc(sizeof(UITextItem *) * 4); m_iNumIDs = 1; - m_iID = (int *)mem_malloc(sizeof(int) * 1); + m_iID = mem_rmalloc(1); // make sure mallocs are ok ASSERT((m_hsList) && (m_tiList) && (m_iID)); // adjust the curr x/y for the checkbox @@ -923,7 +923,7 @@ void ConfigItem::Add(int count, ...) { m_rbCount = count; m_rbList = (UIRadioButton **)mem_malloc(sizeof(UIRadioButton *) * m_rbCount); m_iNumIDs = count; - m_iID = (int *)mem_malloc(sizeof(int) * m_iNumIDs); + m_iID = mem_rmalloc(m_iNumIDs); // make sure mallocs are ok ASSERT((m_tiList) && (m_rbList) && (m_iID)); // adjust the curr x/y for the list of radio buttons diff --git a/Descent3/LoadLevel.cpp b/Descent3/LoadLevel.cpp index 48852b26..fe87e551 100644 --- a/Descent3/LoadLevel.cpp +++ b/Descent3/LoadLevel.cpp @@ -2978,7 +2978,7 @@ void ReadBNodeChunk(CFILE *fp, int version) { ASSERT(!(i <= Highest_room_index && (Rooms[i].flags & RF_EXTERNAL) && bnlist->num_nodes > 0)); if (bnlist->num_nodes) { - bnlist->nodes = (bn_node *)mem_malloc(sizeof(bn_node) * bnlist->num_nodes); + bnlist->nodes = mem_rmalloc(bnlist->num_nodes); for (j = 0; j < bnlist->num_nodes; j++) { bnlist->nodes[j].pos.x = cf_ReadFloat(fp); bnlist->nodes[j].pos.y = cf_ReadFloat(fp); @@ -2986,7 +2986,7 @@ void ReadBNodeChunk(CFILE *fp, int version) { bnlist->nodes[j].num_edges = cf_ReadShort(fp); if (bnlist->nodes[j].num_edges) { - bnlist->nodes[j].edges = (bn_edge *)mem_malloc(sizeof(bn_edge) * bnlist->nodes[j].num_edges); + bnlist->nodes[j].edges = mem_rmalloc(bnlist->nodes[j].num_edges); for (k = 0; k < bnlist->nodes[j].num_edges; k++) { bnlist->nodes[j].edges[k].end_room = cf_ReadShort(fp); bnlist->nodes[j].edges[k].end_index = cf_ReadByte(fp); @@ -3134,15 +3134,15 @@ void ReadRoomAABBChunk(CFILE *fp, int version) { Rooms[i].bbf_max_xyz.z = cf_ReadFloat(fp); Rooms[i].num_bbf_regions = cf_ReadShort(fp); - Rooms[i].num_bbf = (int16_t *)mem_malloc(sizeof(int16_t) * Rooms[i].num_bbf_regions); + Rooms[i].num_bbf = mem_rmalloc(Rooms[i].num_bbf_regions); Rooms[i].bbf_list = (int16_t **)mem_malloc(sizeof(int16_t *) * Rooms[i].num_bbf_regions); - Rooms[i].bbf_list_min_xyz = (vector *)mem_malloc(sizeof(vector) * Rooms[i].num_bbf_regions); - Rooms[i].bbf_list_max_xyz = (vector *)mem_malloc(sizeof(vector) * Rooms[i].num_bbf_regions); + Rooms[i].bbf_list_min_xyz = mem_rmalloc(Rooms[i].num_bbf_regions); + Rooms[i].bbf_list_max_xyz = mem_rmalloc(Rooms[i].num_bbf_regions); Rooms[i].bbf_list_sector = (uint8_t *)mem_malloc(sizeof(char) * Rooms[i].num_bbf_regions); for (j = 0; j < Rooms[i].num_bbf_regions; j++) { Rooms[i].num_bbf[j] = cf_ReadShort(fp); - Rooms[i].bbf_list[j] = (int16_t *)mem_malloc(sizeof(int16_t) * Rooms[i].num_bbf[j]); + Rooms[i].bbf_list[j] = mem_rmalloc(Rooms[i].num_bbf[j]); } for (j = 0; j < Rooms[i].num_bbf_regions; j++) { diff --git a/Descent3/Mission.cpp b/Descent3/Mission.cpp index 3dcad965..dcde32a1 100644 --- a/Descent3/Mission.cpp +++ b/Descent3/Mission.cpp @@ -773,7 +773,7 @@ void ResetMission() { #if (defined(OEM) || defined(DEMO)) bool DemoMission(int mode = 0) { tMission *msn = &Current_mission; - tLevelNode *lvls = (tLevelNode *)mem_malloc(sizeof(tLevelNode) * 5); + tLevelNode *lvls = mem_rmalloc(5); msn->cur_level = 1; msn->num_levels = 1; msn->levels = lvls; @@ -1071,7 +1071,7 @@ bool LoadMission(const char *mssn) { strcpy(errtext, TXT_MSN_LVLNUMINVALID); goto msnfile_error; } - lvls = (tLevelNode *)mem_malloc(sizeof(tLevelNode) * value); + lvls = mem_rmalloc(value); memset(lvls, 0, sizeof(tLevelNode) * value); numlevels = value; } diff --git a/Descent3/ObjInit.cpp b/Descent3/ObjInit.cpp index d6781955..81393214 100644 --- a/Descent3/ObjInit.cpp +++ b/Descent3/ObjInit.cpp @@ -652,7 +652,7 @@ void ObjSetRenderPolyobj(object *objp, int model_num, int dying_model_num) { objp->attach_children = NULL; } if ((objp->attach_children == NULL) && pm->n_attach) { - objp->attach_children = (int *)mem_malloc(sizeof(int) * pm->n_attach); + objp->attach_children = mem_rmalloc(pm->n_attach); if (objp->type == OBJ_PLAYER) ASSERT(pm->n_attach >= NUM_PLAYER_ATTACH_POINTS); for (int i = 0; i < pm->n_attach; i++) @@ -710,7 +710,7 @@ int ObjInitPlayer(object *objp) { // These are always set for a player objp->mtype.phys_info.num_bounces = PHYSICS_UNLIMITED_BOUNCE; if (objp->dynamic_wb == NULL) { - objp->dynamic_wb = (dynamic_wb_info *)mem_malloc(sizeof(dynamic_wb_info) * MAX_WBS_PER_OBJ); + objp->dynamic_wb = mem_rmalloc(MAX_WBS_PER_OBJ); } WBClearInfo(objp); // Set a few misc things @@ -820,7 +820,7 @@ int ObjInitGeneric(object *objp, bool reinit) { objp->dynamic_wb = NULL; } if ((objp->dynamic_wb == NULL) && num_wbs) { - objp->dynamic_wb = (dynamic_wb_info *)mem_malloc(sizeof(dynamic_wb_info) * num_wbs); + objp->dynamic_wb = mem_rmalloc(num_wbs); } // Setup the weapon batteries (must be after polymodel stuff) WBClearInfo(objp); diff --git a/Descent3/PilotPicsAPI.cpp b/Descent3/PilotPicsAPI.cpp index 8eb83c2e..7d8de7cc 100644 --- a/Descent3/PilotPicsAPI.cpp +++ b/Descent3/PilotPicsAPI.cpp @@ -516,8 +516,8 @@ bool PPic_BuildDatabases(void) { // allocate all the memory we're going to need // ------------------------------------------- - Pilot_id_to_offset = (tPilotPicIdOffset *)mem_malloc(sizeof(tPilotPicIdOffset) * PilotPic_count); - Sorted_Pilot_id_to_offset = (uint16_t *)mem_malloc(sizeof(uint16_t) * PilotPic_count); + Pilot_id_to_offset = mem_rmalloc(PilotPic_count); + Sorted_Pilot_id_to_offset = mem_rmalloc(PilotPic_count); if (!Pilot_id_to_offset) { // out of memory!!! LOG_FATAL << "PPIC: Out of memory allocating index database"; diff --git a/Descent3/TelCom.cpp b/Descent3/TelCom.cpp index dae310d9..f493cccb 100644 --- a/Descent3/TelCom.cpp +++ b/Descent3/TelCom.cpp @@ -831,7 +831,7 @@ bool TelComShow(bool ingame, bool ShipSelect) { if (hotspotmap.num_of_hotspots) { int TelCom_onbmp = bm_AllocLoadFileBitmap(IGNORE_TABLE(TELCOM_DISPLAY_OGF_ON), 0); if (TelCom_onbmp != -1) { - hotspot_bitmaps = (chunked_bitmap *)mem_malloc(sizeof(chunked_bitmap) * hotspotmap.num_of_hotspots); + hotspot_bitmaps = mem_rmalloc(hotspotmap.num_of_hotspots); ASSERT(hotspot_bitmaps); CompressTelComOnImage(TelCom_onbmp, hotspot_bitmaps); bm_FreeBitmap(TelCom_onbmp); @@ -1970,7 +1970,7 @@ void TelcomLoadHiLites(const char *filelist[], int monitor, int xoff, int yoff) if (!TelcomHiLiteCount[monitor]) TelcomHiLites[monitor] = NULL; - TelcomHiLites[monitor] = (int *)mem_malloc(sizeof(int) * TelcomHiLiteCount[monitor]); + TelcomHiLites[monitor] = mem_rmalloc(TelcomHiLiteCount[monitor]); if (!TelcomHiLites[monitor]) { LOG_DEBUG.printf("Unable to allocate memory for hilights monitor=%d", monitor); TelcomHiLiteCount[monitor] = 0; diff --git a/Descent3/TelComAutoMap.cpp b/Descent3/TelComAutoMap.cpp index 406bd875..2f0b030a 100644 --- a/Descent3/TelComAutoMap.cpp +++ b/Descent3/TelComAutoMap.cpp @@ -269,7 +269,7 @@ bool TelComAutoMap(tTelComInfo *tcs) { bool done = false; if (!AM_rotated_points) { - AM_rotated_points = (g3Point *)mem_malloc(sizeof(g3Point) * MAX_VERTS_PER_ROOM); + AM_rotated_points = mem_rmalloc(MAX_VERTS_PER_ROOM); } AM_tcs = tcs; AM_current_marker = -1; diff --git a/Descent3/TelComEffects.cpp b/Descent3/TelComEffects.cpp index f1941b86..629d14af 100644 --- a/Descent3/TelComEffects.cpp +++ b/Descent3/TelComEffects.cpp @@ -1202,7 +1202,7 @@ bool CreateBmpStretch(tceffect *tce, const char *filename) { int total = w_count * h_count; int index; tce->bmpinfo.bm_count = total; - tce->bmpinfo.bitmaps = (int *)mem_malloc(sizeof(int) * total); + tce->bmpinfo.bitmaps = mem_rmalloc(total); if (!tce->bmpinfo.bitmaps) return false; diff --git a/Descent3/TelComGoals.cpp b/Descent3/TelComGoals.cpp index af0ebc46..b51e6640 100644 --- a/Descent3/TelComGoals.cpp +++ b/Descent3/TelComGoals.cpp @@ -188,9 +188,9 @@ void TCGoalsBuildLineData(void) { //'count' goals are what we have to display // allocate memory needed and start filling in if (count) { - TG_Lines = (tGoalLineInfo *)mem_malloc(sizeof(tGoalLineInfo) * count); + TG_Lines = mem_rmalloc(count); TG_NumLines = count; - TG_SortedList = (int *)mem_malloc(sizeof(int) * count); + TG_SortedList = mem_rmalloc(count); if (!TG_SortedList || !TG_Lines) { // out of memory Telcom_system.current_status = TS_OFF; diff --git a/Descent3/bsp.cpp b/Descent3/bsp.cpp index fdcb1487..86fa9619 100644 --- a/Descent3/bsp.cpp +++ b/Descent3/bsp.cpp @@ -171,7 +171,7 @@ bsppolygon *NewPolygon(int roomnum, int facenum, int numverts) { return NULL; } - verts = (vector *)mem_malloc(sizeof(vector) * numverts); + verts = mem_rmalloc(numverts); ASSERT(verts != NULL); newpoly->nv = numverts; diff --git a/Descent3/gametexture.cpp b/Descent3/gametexture.cpp index 33f7797f..48375213 100644 --- a/Descent3/gametexture.cpp +++ b/Descent3/gametexture.cpp @@ -452,7 +452,7 @@ int AllocateProceduralForTexture(int handle) { // Allocates the memory needed for static elements for a procedural texture void AllocateStaticProceduralsForTexture(int handle, int num_elements) { GameTextures[handle].procedural->static_proc_elements = - (static_proc_element *)mem_malloc(sizeof(static_proc_element) * num_elements); + mem_rmalloc(num_elements); ASSERT(GameTextures[handle].procedural->static_proc_elements); } diff --git a/Descent3/hotspotmap.cpp b/Descent3/hotspotmap.cpp index 466e1cb2..5009d7b5 100644 --- a/Descent3/hotspotmap.cpp +++ b/Descent3/hotspotmap.cpp @@ -175,7 +175,7 @@ int CreateHotSpotMap(const char *map, int width, int height, hotspotmap_t *hsmap if (!num_hs) return -1; - hsmap->hs = (hotspot *)mem_malloc(sizeof(hotspot) * num_hs); + hsmap->hs = mem_rmalloc(num_hs); ASSERT(hsmap->hs); for (count = 0; count < num_hs; count++) { if (whats_there[count] == HOTSPOT_THERE) { @@ -220,7 +220,7 @@ int CreateHotSpotMap(const char *map, int width, int height, hotspotmap_t *hsmap // fill in the struct with the start and end values for each scanline hsmap->hs[count].scanlines = sl_count; if (sl_count) { - hsmap->hs[count].x = (scanline *)mem_malloc(sizeof(scanline) * sl_count); + hsmap->hs[count].x = mem_rmalloc(sl_count); ASSERT(hsmap->hs[count].x); memset(hsmap->hs[count].x, 0, sizeof(scanline) * sl_count); y = hsmap->hs[count].starting_y; @@ -268,7 +268,7 @@ void CreateWindowMap(const char *map, int width, int height, windowmap_t *wndmap uint8_t alpha; bool newline = true; - wndmap->wm = (window_box *)mem_malloc(sizeof(window_box) * wndmap->num_of_windows); + wndmap->wm = mem_rmalloc(wndmap->num_of_windows); ASSERT(wndmap->wm); for (int index = 0; index < wndmap->num_of_windows; index++) { @@ -681,13 +681,13 @@ void menutga_LoadHotSpotMap(int back_bmp, const char *filename, hotspotmap_t *hs int curr_hs, curr_sl, num_sl; - hsmap->hs = (hotspot *)mem_malloc(sizeof(hotspot) * hsmap->num_of_hotspots); + hsmap->hs = mem_rmalloc(hsmap->num_of_hotspots); memset(hsmap->hs, 0, sizeof(hotspot) * hsmap->num_of_hotspots); for (curr_hs = 0; curr_hs < hsmap->num_of_hotspots; curr_hs++) { hsmap->hs[curr_hs].starting_y = cf_ReadInt(infile); num_sl = hsmap->hs[curr_hs].scanlines = cf_ReadInt(infile); if (num_sl) { - hsmap->hs[curr_hs].x = (scanline *)mem_malloc(sizeof(scanline) * hsmap->hs[curr_hs].scanlines); + hsmap->hs[curr_hs].x = mem_rmalloc(hsmap->hs[curr_hs].scanlines); memset(hsmap->hs[curr_hs].x, 0, sizeof(scanline) * hsmap->hs[curr_hs].scanlines); for (curr_sl = 0; curr_sl < hsmap->hs[curr_hs].scanlines; curr_sl++) { hsmap->hs[curr_hs].x[curr_sl].start = cf_ReadInt(infile); @@ -702,7 +702,7 @@ void menutga_LoadHotSpotMap(int back_bmp, const char *filename, hotspotmap_t *hs wndmap->num_of_windows = cf_ReadInt(infile); LOG_DEBUG.printf("Loading hotspotmap %s Contains: (%d hotspots) (%d Windows)", filename, hsmap->num_of_hotspots, wndmap->num_of_windows); - wndmap->wm = (window_box *)mem_malloc(sizeof(window_box) * wndmap->num_of_windows); + wndmap->wm = mem_rmalloc(wndmap->num_of_windows); for (count = 0; count < wndmap->num_of_windows; count++) { wndmap->wm[count].x = cf_ReadInt(infile); wndmap->wm[count].y = cf_ReadInt(infile); diff --git a/Descent3/lighting.cpp b/Descent3/lighting.cpp index c0a86796..1fb9614d 100644 --- a/Descent3/lighting.cpp +++ b/Descent3/lighting.cpp @@ -140,7 +140,7 @@ void InitDynamicLighting() { Dynamic_lightmap_memory = (uint16_t *)mem_malloc(DYNAMIC_LIGHTMAP_MEMORY); // Init our records list - Dynamic_lightmaps = (dynamic_lightmap *)mem_malloc(sizeof(dynamic_lightmap) * MAX_DYNAMIC_LIGHTMAPS); + Dynamic_lightmaps = mem_rmalloc(MAX_DYNAMIC_LIGHTMAPS); ASSERT(Dynamic_lightmaps); for (i = 0; i < MAX_DYNAMIC_LIGHTMAPS; i++) { diff --git a/Descent3/loadstate.cpp b/Descent3/loadstate.cpp index d009ba15..816926af 100644 --- a/Descent3/loadstate.cpp +++ b/Descent3/loadstate.cpp @@ -1125,7 +1125,7 @@ int LGSObjects(CFILE *fp, int version) { if (f_allocated) { // mprintf(0,"Object %d has %d attach points.\n",i,nattach); - op->attach_children = (int *)mem_malloc(sizeof(int) * nattach); + op->attach_children = mem_rmalloc(nattach); for (j = 0; j < nattach; j++) gs_ReadInt(fp, op->attach_children[j]); } @@ -1310,8 +1310,8 @@ int LGSObjects(CFILE *fp, int version) { int cur = 0; p_info->multi_turret_info.time = 0; - p_info->multi_turret_info.keyframes = (float *)mem_malloc(sizeof(float) * count); - p_info->multi_turret_info.last_keyframes = (float *)mem_malloc(sizeof(float) * count); + p_info->multi_turret_info.keyframes = mem_rmalloc(count); + p_info->multi_turret_info.last_keyframes = mem_rmalloc(count); p_info->multi_turret_info.flags = 0; } // Do Animation stuff @@ -1548,7 +1548,7 @@ int LGSObjWB(CFILE *fp, object *op) { if (!num_wbs) return LGS_OK; - dwba = (dynamic_wb_info *)mem_malloc(sizeof(dynamic_wb_info) * num_wbs); + dwba = mem_rmalloc(num_wbs); for (i = 0; i < num_wbs; i++) { dynamic_wb_info *dwb = &dwba[i]; diff --git a/Descent3/matcen.cpp b/Descent3/matcen.cpp index a0004a4a..b6742f21 100644 --- a/Descent3/matcen.cpp +++ b/Descent3/matcen.cpp @@ -920,7 +920,7 @@ void matcen::LoadData(CFILE *fp) { m_max_alive_children = cf_ReadShort(fp); if (m_max_alive_children > 0) { m_num_alive = cf_ReadShort(fp); - m_alive_list = (int *)mem_malloc(sizeof(int) * m_max_alive_children); + m_alive_list = mem_rmalloc(m_max_alive_children); for (i = 0; i < m_num_alive; i++) { m_alive_list[i] = cf_ReadInt(fp); @@ -1784,7 +1784,7 @@ bool matcen::SetMaxAliveChildren(int max_alive) { // Allocate the alive children list if (max_alive > 0) { - temp = (int *)mem_malloc(sizeof(int) * max_alive); + temp = mem_rmalloc(max_alive); } else { temp = NULL; } diff --git a/Descent3/object.cpp b/Descent3/object.cpp index c1b84955..74846ed7 100644 --- a/Descent3/object.cpp +++ b/Descent3/object.cpp @@ -3352,8 +3352,8 @@ void SetObjectControlType(object *obj, int control_type) { int cur = 0; p_info->multi_turret_info.time = 0; - p_info->multi_turret_info.keyframes = (float *)mem_malloc(sizeof(float) * count); - p_info->multi_turret_info.last_keyframes = (float *)mem_malloc(sizeof(float) * count); + p_info->multi_turret_info.keyframes = mem_rmalloc(count); + p_info->multi_turret_info.last_keyframes = mem_rmalloc(count); p_info->multi_turret_info.flags = 0; } } @@ -3366,10 +3366,10 @@ void SetObjectControlType(object *obj, int control_type) { if (obj->dynamic_wb == NULL) { if (obj->type == OBJ_PLAYER) { - obj->dynamic_wb = (dynamic_wb_info *)mem_malloc(sizeof(dynamic_wb_info) * MAX_WBS_PER_OBJ); + obj->dynamic_wb = mem_rmalloc(MAX_WBS_PER_OBJ); } else { if (num_wbs) - obj->dynamic_wb = (dynamic_wb_info *)mem_malloc(sizeof(dynamic_wb_info) * num_wbs); + obj->dynamic_wb = mem_rmalloc(num_wbs); } } } diff --git a/Descent3/objinfo.cpp b/Descent3/objinfo.cpp index 8f4e755f..3af2fd9f 100644 --- a/Descent3/objinfo.cpp +++ b/Descent3/objinfo.cpp @@ -122,13 +122,13 @@ int AllocObjectID(int type, bool f_anim, bool f_weapons, bool f_ai) { } // Make sure the weapon battery info is cleared for a new object if (f_weapons) { - Object_info[i].static_wb = (otype_wb_info *)mem_malloc(sizeof(otype_wb_info) * MAX_WBS_PER_OBJ); + Object_info[i].static_wb = mem_rmalloc(MAX_WBS_PER_OBJ); memset(Object_info[i].static_wb, 0, sizeof(otype_wb_info) * MAX_WBS_PER_OBJ); WBClearInfo(Object_info[i].static_wb); } if (f_anim) { - Object_info[i].anim = (anim_elem *)mem_malloc(sizeof(anim_elem) * NUM_MOVEMENT_CLASSES); + Object_info[i].anim = mem_rmalloc(NUM_MOVEMENT_CLASSES); memset(Object_info[i].anim, 0, sizeof(anim_elem) * NUM_MOVEMENT_CLASSES); for (j = 0; j < NUM_MOVEMENT_CLASSES; j++) for (k = 0; k < NUM_ANIMS_PER_CLASS; k++) { diff --git a/Descent3/osiris_predefs.cpp b/Descent3/osiris_predefs.cpp index 55714695..762bf8e8 100644 --- a/Descent3/osiris_predefs.cpp +++ b/Descent3/osiris_predefs.cpp @@ -3324,7 +3324,7 @@ int osipf_AIGetNearbyObjs(vector *pos, int init_roomnum, float rad, int *object_ int i; int count = 0; - s_list = (int16_t *)mem_malloc(sizeof(int16_t) * max_elements); + s_list = mem_rmalloc(max_elements); num_close = fvi_QuickDistObjectList(pos, init_roomnum, rad, s_list, max_elements, f_lightmap_only, f_only_players_and_ais, f_include_non_collide_objects, f_stop_at_closed_doors); diff --git a/Descent3/pilot.cpp b/Descent3/pilot.cpp index 284ced02..d86d5388 100644 --- a/Descent3/pilot.cpp +++ b/Descent3/pilot.cpp @@ -2359,7 +2359,7 @@ bool PltSelectShip(pilot *Pilot) { if (Ships[i].used) count++; } - ship_info.idlist = (int *)mem_malloc(sizeof(int) * count); + ship_info.idlist = mem_rmalloc(count); if (!ship_info.idlist) goto ship_id_err; diff --git a/Descent3/pilot_class.cpp b/Descent3/pilot_class.cpp index 3ad2fc6c..7bfb8579 100644 --- a/Descent3/pilot_class.cpp +++ b/Descent3/pilot_class.cpp @@ -1279,7 +1279,7 @@ void pilot::read_mission_data(CFILE *file, bool skip) { mem_free(mission_data); mission_data = NULL; } - mission_data = (tMissionData *)mem_malloc(sizeof(tMissionData) * num_missions_flown); + mission_data = mem_rmalloc(num_missions_flown); if (!mission_data) { // out of memory num_missions_flown = 0; diff --git a/Descent3/viseffect.cpp b/Descent3/viseffect.cpp index c462bee6..f3dddfcf 100644 --- a/Descent3/viseffect.cpp +++ b/Descent3/viseffect.cpp @@ -499,9 +499,9 @@ void InitVisEffects() { VisDeadList = (uint16_t *)mem_realloc(VisDeadList, sizeof(uint16_t) * max_vis_effects); Vis_free_list = (int16_t *)mem_realloc(Vis_free_list, sizeof(int16_t) * max_vis_effects); } else if (VisEffects == NULL) { - VisEffects = (vis_effect *)mem_malloc(sizeof(vis_effect) * max_vis_effects); - VisDeadList = (uint16_t *)mem_malloc(sizeof(uint16_t) * max_vis_effects); - Vis_free_list = (int16_t *)mem_malloc(sizeof(int16_t) * max_vis_effects); + VisEffects = mem_rmalloc(max_vis_effects); + VisDeadList = mem_rmalloc(max_vis_effects); + Vis_free_list = mem_rmalloc(max_vis_effects); } for (int i = 0; i < max_vis_effects; i++) { VisEffects[i].type = VIS_NONE; diff --git a/cfile/cfile.cpp b/cfile/cfile.cpp index d6d525c9..1bd62135 100644 --- a/cfile/cfile.cpp +++ b/cfile/cfile.cpp @@ -454,7 +454,7 @@ CFILE *open_file_in_directory(const std::filesystem::path &filename, const char cfile = (CFILE *)mem_malloc(sizeof(*cfile)); if (!cfile) Error("Out of memory in open_file_in_directory()"); - cfile->name = (char *)mem_malloc(sizeof(char) * (strlen(using_filename.u8string().c_str()) + 1)); + cfile->name = mem_rmalloc((strlen(using_filename.u8string().c_str()) + 1)); if (!cfile->name) Error("Out of memory in open_file_in_directory()"); strcpy(cfile->name, using_filename.u8string().c_str()); diff --git a/ddio/lnxfile.cpp b/ddio/lnxfile.cpp index 7f07ec3d..e816ded5 100644 --- a/ddio/lnxfile.cpp +++ b/ddio/lnxfile.cpp @@ -333,7 +333,7 @@ void ddio_CleanPath(char *dest, const char *srcPath) { // now the fun part, figure out the correct order of the directories int *dir_order; - dir_order = (int *)mem_malloc(sizeof(int) * dirs); + dir_order = mem_rmalloc(dirs); if (!dir_order) { strcpy(dest, srcPath); return; diff --git a/ddio/winfile.cpp b/ddio/winfile.cpp index 397b9b96..9a9b8071 100644 --- a/ddio/winfile.cpp +++ b/ddio/winfile.cpp @@ -412,7 +412,7 @@ void ddio_CleanPath(char *dest, const char *srcPath) { // now the fun part, figure out the correct order of the directories int *dir_order; - dir_order = (int *)mem_malloc(sizeof(int) * dirs); + dir_order = mem_rmalloc(dirs); if (!dir_order) { strcpy(dest, srcPath); return; diff --git a/editor/BriefEdit.cpp b/editor/BriefEdit.cpp index 480f8694..b2dc8e6a 100644 --- a/editor/BriefEdit.cpp +++ b/editor/BriefEdit.cpp @@ -1915,7 +1915,7 @@ void CBriefEdit::ParseLayoutScreenFile(char *filename) { return; } - layouts = (tLayoutScreen *)mem_malloc(sizeof(tLayoutScreen) * num_layouts); + layouts = mem_rmalloc(num_layouts); if (!layouts) { mprintf(0, "Out of memory loading layout screens...trying to load %d screens\n", num_layouts); num_layouts = 0; diff --git a/editor/DallasMainDlg.cpp b/editor/DallasMainDlg.cpp index f004a0ff..13eec37b 100644 --- a/editor/DallasMainDlg.cpp +++ b/editor/DallasMainDlg.cpp @@ -3525,7 +3525,7 @@ int CDallasMainDlg::GetLowestUnusedScriptID(void) { max_size = GetChildCount(TVI_ROOT); if (max_size == 0) return (lowest_id); - list = (int *)mem_malloc(sizeof(int) * max_size); + list = mem_rmalloc(max_size); if (list == NULL) return (m_NextScriptID); @@ -7502,7 +7502,7 @@ int CDallasMainDlg::AddNodeToScriptOwnerGroup(int pos, HTREEITEM script_node) { // Add this node to the appropriate event section list if (event_section->num_script_nodes == 0) - event_section->script_node_list = (HTREEITEM *)mem_malloc(sizeof(HTREEITEM) * 1); + event_section->script_node_list = mem_rmalloc(1); else event_section->script_node_list = (HTREEITEM *)mem_realloc( event_section->script_node_list, sizeof(HTREEITEM) * (event_section->num_script_nodes + 1)); @@ -7552,7 +7552,7 @@ int CDallasMainDlg::AddNodeToScriptGroupingList(HTREEITEM script_node) { // Since owner does not exist, create a new Script Group entry if (m_NumScriptGroups == 0) - m_ScriptGroupingList = (tScriptOwnerGroup *)mem_malloc(sizeof(tScriptOwnerGroup) * 1); + m_ScriptGroupingList = mem_rmalloc(1); else m_ScriptGroupingList = (tScriptOwnerGroup *)mem_realloc(m_ScriptGroupingList, sizeof(tScriptOwnerGroup) * (m_NumScriptGroups + 1)); diff --git a/editor/FilePageAddDlg.cpp b/editor/FilePageAddDlg.cpp index 27770b5b..5f8a16a1 100644 --- a/editor/FilePageAddDlg.cpp +++ b/editor/FilePageAddDlg.cpp @@ -411,7 +411,7 @@ bool CFilePageAddDlg::Quit(void) { return true; } - int *sel_items = (int *)mem_malloc(sizeof(int) * m_NumberOfSelectedFiles); + int *sel_items = mem_rmalloc(m_NumberOfSelectedFiles); if (!sel_items) { mem_free(m_SelectedFiles); m_SelectedFiles = NULL; diff --git a/editor/FilePageDialog.cpp b/editor/FilePageDialog.cpp index 2e9113bc..8f538c11 100644 --- a/editor/FilePageDialog.cpp +++ b/editor/FilePageDialog.cpp @@ -184,7 +184,7 @@ int CFilePageDialog::CreateIndexMap(int **index_map, int listbox_id) { int *map; - map = *index_map = (int *)mem_malloc(sizeof(int) * listbox_count); + map = *index_map = mem_rmalloc(listbox_count); if (!map) return 0; n = 0; diff --git a/editor/ScriptSyncDialog.cpp b/editor/ScriptSyncDialog.cpp index 72a58cd7..ec8071fc 100644 --- a/editor/ScriptSyncDialog.cpp +++ b/editor/ScriptSyncDialog.cpp @@ -308,7 +308,7 @@ void CScriptSyncDialog::BuildList(void) { if (m_NumFiles == 0) return; - m_Files = (tFileInfo *)mem_malloc(sizeof(tFileInfo) * m_NumFiles); + m_Files = mem_rmalloc(m_NumFiles); m_NumFiles = 0; if (ManageFindFirst(buffer, "*.cpp")) { diff --git a/editor/editor_lighting.cpp b/editor/editor_lighting.cpp index c5dc707d..f3b0f7a0 100644 --- a/editor/editor_lighting.cpp +++ b/editor/editor_lighting.cpp @@ -1038,13 +1038,13 @@ void DoRadiosityForRooms() { // Setup satellites for (i = 0; i < Terrain_sky.num_satellites; i++, surface_index++) { - Light_surfaces[surface_index].verts = (vector *)mem_malloc(sizeof(vector) * 3); + Light_surfaces[surface_index].verts = mem_rmalloc(3); ASSERT(Light_surfaces[surface_index].verts != NULL); Light_surfaces[surface_index].elements = mem_rmalloc(); ASSERT(Light_surfaces[surface_index].elements != NULL); - Light_surfaces[surface_index].elements[0].verts = (vector *)mem_malloc(sizeof(vector) * 3); + Light_surfaces[surface_index].elements[0].verts = mem_rmalloc(3); ASSERT(Light_surfaces[surface_index].elements[0].verts); Light_surfaces[surface_index].surface_type = ST_SATELLITE; @@ -1558,7 +1558,7 @@ void ClipSurfaceElement(vector *surf_verts, rad_element *ep, vector *clip_verts, if (ep->num_verts == 0) ep->flags |= EF_IGNORE; else { - ep->verts = (vector *)mem_malloc(sizeof(vector) * nnv); + ep->verts = mem_rmalloc(nnv); ASSERT(ep->verts); for (i = 0; i < nnv; i++) { @@ -1914,10 +1914,10 @@ void DoRadiosityForTerrain() { Light_surfaces[i * 2].elements = mem_rmalloc(); ASSERT(Light_surfaces[i * 2].elements != NULL); - Light_surfaces[i * 2].elements[0].verts = (vector *)mem_malloc(sizeof(vector) * 3); + Light_surfaces[i * 2].elements[0].verts = mem_rmalloc(3); ASSERT(Light_surfaces[i * 2].elements[0].verts); - Light_surfaces[i * 2].verts = (vector *)mem_malloc(sizeof(vector) * 3); + Light_surfaces[i * 2].verts = mem_rmalloc(3); ASSERT(Light_surfaces[i * 2].verts != NULL); Light_surfaces[i * 2].normal = TerrainNormals[MAX_TERRAIN_LOD - 1][seg].normal1; @@ -1954,10 +1954,10 @@ void DoRadiosityForTerrain() { Light_surfaces[i * 2 + 1].elements = mem_rmalloc(); ASSERT(Light_surfaces[i * 2 + 1].elements != NULL); - Light_surfaces[i * 2 + 1].elements[0].verts = (vector *)mem_malloc(sizeof(vector) * 3); + Light_surfaces[i * 2 + 1].elements[0].verts = mem_rmalloc(3); ASSERT(Light_surfaces[i * 2 + 1].elements[0].verts); - Light_surfaces[i * 2 + 1].verts = (vector *)mem_malloc(sizeof(vector) * 3); + Light_surfaces[i * 2 + 1].verts = mem_rmalloc(3); ASSERT(Light_surfaces[i * 2 + 1].verts != NULL); Light_surfaces[i * 2 + 1].normal = TerrainNormals[MAX_TERRAIN_LOD - 1][seg].normal2; @@ -1993,13 +1993,13 @@ void DoRadiosityForTerrain() { // Setup satellites for (i = 0; i < Terrain_sky.num_satellites; i++, surf_index++) { - Light_surfaces[surf_index].verts = (vector *)mem_malloc(sizeof(vector) * 3); + Light_surfaces[surf_index].verts = mem_rmalloc(3); ASSERT(Light_surfaces[surf_index].verts != NULL); Light_surfaces[surf_index].elements = mem_rmalloc(); ASSERT(Light_surfaces[surf_index].elements != NULL); - Light_surfaces[surf_index].elements[0].verts = (vector *)mem_malloc(sizeof(vector) * 3); + Light_surfaces[surf_index].elements[0].verts = mem_rmalloc(3); ASSERT(Light_surfaces[surf_index].elements[0].verts); Light_surfaces[surf_index].surface_type = ST_SATELLITE; @@ -3312,7 +3312,7 @@ void SetupSpecularLighting(int external) { room *rp = &Rooms[i]; // Calculate vertex normals for this room - vector *vertnorms = (vector *)mem_malloc(sizeof(vector) * rp->num_verts); + vector *vertnorms = mem_rmalloc(rp->num_verts); ASSERT(vertnorms); for (t = 0; t < rp->num_verts; t++) { int total = 0; @@ -3336,7 +3336,7 @@ void SetupSpecularLighting(int external) { } for (t = 0; t < 4; t++) { - Room_strongest_value[i][t] = (float *)mem_malloc(sizeof(float) * rp->num_faces); + Room_strongest_value[i][t] = mem_rmalloc(rp->num_faces); ASSERT(Room_strongest_value[i][t]); memset(Room_strongest_value[i][t], 0, sizeof(float) * rp->num_faces); } diff --git a/grtext/grfont.cpp b/grtext/grfont.cpp index af688d97..f4cf5e60 100644 --- a/grtext/grfont.cpp +++ b/grtext/grfont.cpp @@ -331,7 +331,7 @@ int grfont_Load(const char *fname) { // Read in all widths if (fnt.flags & FT_PROPORTIONAL) { - fnt.char_widths = (uint8_t *)mem_malloc(sizeof(uint8_t) * num_char); + fnt.char_widths = mem_rmalloc(num_char); for (i = 0; i < num_char; i++) fnt.char_widths[i] = (uint8_t)READ_FONT_SHORT(ff); } else { @@ -578,7 +578,7 @@ bool grfont_SetTemplate(const char *pathname, const tFontTemplate *ft) { // Read in all widths if (fnt.flags & FT_PROPORTIONAL) { - fnt.char_widths = (uint8_t *)mem_malloc(sizeof(uint8_t) * num_char); + fnt.char_widths = mem_rmalloc(num_char); for (i = 0; i < num_char; i++) fnt.char_widths[i] = (uint8_t)READ_FONT_SHORT(ffin); } else { diff --git a/manage/pagelock.cpp b/manage/pagelock.cpp index 2f4fa167..c5ca7152 100644 --- a/manage/pagelock.cpp +++ b/manage/pagelock.cpp @@ -661,7 +661,7 @@ int mng_DeleteDuplicatePagelocks() { mngs_Pagelock *already_read; int num = 0, duplicates = 0, i; - already_read = (mngs_Pagelock *)mem_malloc(sizeof(mngs_Pagelock) * 8000); + already_read = mem_rmalloc(8000); ASSERT(already_read); infile = (CFILE *)cfopen(TableLockFilename, "rb"); diff --git a/model/polymodel.cpp b/model/polymodel.cpp index 51aa395b..0247fa50 100644 --- a/model/polymodel.cpp +++ b/model/polymodel.cpp @@ -1330,7 +1330,7 @@ int ReadNewModelFile(int polynum, CFILE *infile) { pm->n_models = cf_ReadInt(infile); pm->rad = cf_ReadFloat(infile); - pm->submodel = (bsp_info *)mem_malloc(sizeof(bsp_info) * pm->n_models); + pm->submodel = mem_rmalloc(pm->n_models); ASSERT(pm->submodel != nullptr); memset(pm->submodel, 0, sizeof(bsp_info) * pm->n_models); @@ -1494,7 +1494,7 @@ int ReadNewModelFile(int polynum, CFILE *infile) { int *start_index; if (nfaces) { - start_index = (int *)mem_malloc(sizeof(int) * nfaces); + start_index = mem_rmalloc(nfaces); ASSERT(start_index); } else start_index = nullptr; @@ -1617,7 +1617,7 @@ int ReadNewModelFile(int polynum, CFILE *infile) { case ID_GPNT: pm->n_guns = cf_ReadInt(infile); - pm->gun_slots = (w_bank *)mem_malloc(sizeof(w_bank) * pm->n_guns); + pm->gun_slots = mem_rmalloc(pm->n_guns); ASSERT(pm->gun_slots != nullptr); for (i = 0; i < pm->n_guns; i++) { @@ -1638,7 +1638,7 @@ int ReadNewModelFile(int polynum, CFILE *infile) { case ID_ATTACH: pm->n_attach = cf_ReadInt(infile); if (pm->n_attach) { - pm->attach_slots = (a_bank *)mem_malloc(sizeof(a_bank) * pm->n_attach); + pm->attach_slots = mem_rmalloc(pm->n_attach); ASSERT(pm->attach_slots != nullptr); for (i = 0; i < pm->n_attach; i++) { @@ -1691,7 +1691,7 @@ int ReadNewModelFile(int polynum, CFILE *infile) { pm->num_wbs = cf_ReadInt(infile); if (pm->num_wbs) { - pm->poly_wb = (poly_wb_info *)mem_malloc(sizeof(poly_wb_info) * pm->num_wbs); + pm->poly_wb = mem_rmalloc(pm->num_wbs); // Get each individual wb info struct for (i = 0; i < pm->num_wbs; i++) { @@ -1725,7 +1725,7 @@ int ReadNewModelFile(int polynum, CFILE *infile) { case ID_GROUND: pm->n_ground = cf_ReadInt(infile); - pm->ground_slots = (w_bank *)mem_malloc(sizeof(w_bank) * pm->n_ground); + pm->ground_slots = mem_rmalloc(pm->n_ground); ASSERT(pm->ground_slots != nullptr); for (i = 0; i < pm->n_ground; i++) { diff --git a/music/sequencer.cpp b/music/sequencer.cpp index f76e65e6..df0c33cc 100644 --- a/music/sequencer.cpp +++ b/music/sequencer.cpp @@ -178,7 +178,7 @@ bool OutrageMusicSeq::Init(const char *theme_file) { Stop(); // initialize memory buffers - m_ins_buffer = (music_ins *)mem_malloc(sizeof(music_ins) * MAX_MUSIC_INSTRUCTIONS); + m_ins_buffer = mem_rmalloc(MAX_MUSIC_INSTRUCTIONS); m_str_buffer = (char *)mem_malloc(MAX_MUSIC_STRLEN); m_ins_curptr = m_ins_buffer; m_str_curptr = m_str_buffer;