mem_malloc type triviality checks (2/8)

Automated replacement with

```
git grep -l mem_malloc |
xargs perl -i -lpe 's{\((\w+) \*\)mem_malloc\(sizeof\(\1\) \* (\S+)\)}{mem_rmalloc<$1>($2)}'
```
This commit is contained in:
Jan Engelhardt 2024-08-30 13:40:54 +02:00
parent 6fbc86efec
commit c7da9daee2
35 changed files with 86 additions and 86 deletions

View File

@ -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<int16_t>(rp->num_faces);
used = mem_rmalloc<bool>(rp->num_faces);
for (count1 = 0; count1 < rp->num_faces; count1++) {
used[count1] = false;

View File

@ -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<int>(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<int>(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<int>(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<int>(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<int>(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<int>(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<int>(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

View File

@ -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<bn_node>(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<bn_edge>(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<int16_t>(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<vector>(Rooms[i].num_bbf_regions);
Rooms[i].bbf_list_max_xyz = mem_rmalloc<vector>(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<int16_t>(Rooms[i].num_bbf[j]);
}
for (j = 0; j < Rooms[i].num_bbf_regions; j++) {

View File

@ -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<tLevelNode>(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<tLevelNode>(value);
memset(lvls, 0, sizeof(tLevelNode) * value);
numlevels = value;
}

View File

@ -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<int>(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<dynamic_wb_info>(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<dynamic_wb_info>(num_wbs);
}
// Setup the weapon batteries (must be after polymodel stuff)
WBClearInfo(objp);

View File

@ -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<tPilotPicIdOffset>(PilotPic_count);
Sorted_Pilot_id_to_offset = mem_rmalloc<uint16_t>(PilotPic_count);
if (!Pilot_id_to_offset) {
// out of memory!!!
LOG_FATAL << "PPIC: Out of memory allocating index database";

View File

@ -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<chunked_bitmap>(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<int>(TelcomHiLiteCount[monitor]);
if (!TelcomHiLites[monitor]) {
LOG_DEBUG.printf("Unable to allocate memory for hilights monitor=%d", monitor);
TelcomHiLiteCount[monitor] = 0;

View File

@ -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<g3Point>(MAX_VERTS_PER_ROOM);
}
AM_tcs = tcs;
AM_current_marker = -1;

View File

@ -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<int>(total);
if (!tce->bmpinfo.bitmaps)
return false;

View File

@ -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<tGoalLineInfo>(count);
TG_NumLines = count;
TG_SortedList = (int *)mem_malloc(sizeof(int) * count);
TG_SortedList = mem_rmalloc<int>(count);
if (!TG_SortedList || !TG_Lines) {
// out of memory
Telcom_system.current_status = TS_OFF;

View File

@ -171,7 +171,7 @@ bsppolygon *NewPolygon(int roomnum, int facenum, int numverts) {
return NULL;
}
verts = (vector *)mem_malloc(sizeof(vector) * numverts);
verts = mem_rmalloc<vector>(numverts);
ASSERT(verts != NULL);
newpoly->nv = numverts;

View File

@ -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<static_proc_element>(num_elements);
ASSERT(GameTextures[handle].procedural->static_proc_elements);
}

View File

@ -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<hotspot>(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<scanline>(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<window_box>(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<hotspot>(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<scanline>(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<window_box>(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);

View File

@ -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<dynamic_lightmap>(MAX_DYNAMIC_LIGHTMAPS);
ASSERT(Dynamic_lightmaps);
for (i = 0; i < MAX_DYNAMIC_LIGHTMAPS; i++) {

View File

@ -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<int>(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<float>(count);
p_info->multi_turret_info.last_keyframes = mem_rmalloc<float>(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<dynamic_wb_info>(num_wbs);
for (i = 0; i < num_wbs; i++) {
dynamic_wb_info *dwb = &dwba[i];

View File

@ -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<int>(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<int>(max_alive);
} else {
temp = NULL;
}

View File

@ -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<float>(count);
p_info->multi_turret_info.last_keyframes = mem_rmalloc<float>(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<dynamic_wb_info>(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<dynamic_wb_info>(num_wbs);
}
}
}

View File

@ -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<otype_wb_info>(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<anim_elem>(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++) {

View File

@ -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<int16_t>(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);

View File

@ -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<int>(count);
if (!ship_info.idlist)
goto ship_id_err;

View File

@ -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<tMissionData>(num_missions_flown);
if (!mission_data) {
// out of memory
num_missions_flown = 0;

View File

@ -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<vis_effect>(max_vis_effects);
VisDeadList = mem_rmalloc<uint16_t>(max_vis_effects);
Vis_free_list = mem_rmalloc<int16_t>(max_vis_effects);
}
for (int i = 0; i < max_vis_effects; i++) {
VisEffects[i].type = VIS_NONE;

View File

@ -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<char>((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());

View File

@ -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<int>(dirs);
if (!dir_order) {
strcpy(dest, srcPath);
return;

View File

@ -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<int>(dirs);
if (!dir_order) {
strcpy(dest, srcPath);
return;

View File

@ -1915,7 +1915,7 @@ void CBriefEdit::ParseLayoutScreenFile(char *filename) {
return;
}
layouts = (tLayoutScreen *)mem_malloc(sizeof(tLayoutScreen) * num_layouts);
layouts = mem_rmalloc<tLayoutScreen>(num_layouts);
if (!layouts) {
mprintf(0, "Out of memory loading layout screens...trying to load %d screens\n", num_layouts);
num_layouts = 0;

View File

@ -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<int>(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<HTREEITEM>(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<tScriptOwnerGroup>(1);
else
m_ScriptGroupingList =
(tScriptOwnerGroup *)mem_realloc(m_ScriptGroupingList, sizeof(tScriptOwnerGroup) * (m_NumScriptGroups + 1));

View File

@ -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<int>(m_NumberOfSelectedFiles);
if (!sel_items) {
mem_free(m_SelectedFiles);
m_SelectedFiles = NULL;

View File

@ -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<int>(listbox_count);
if (!map)
return 0;
n = 0;

View File

@ -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<tFileInfo>(m_NumFiles);
m_NumFiles = 0;
if (ManageFindFirst(buffer, "*.cpp")) {

View File

@ -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<vector>(3);
ASSERT(Light_surfaces[surface_index].verts != NULL);
Light_surfaces[surface_index].elements = mem_rmalloc<rad_element>();
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<vector>(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<vector>(nnv);
ASSERT(ep->verts);
for (i = 0; i < nnv; i++) {
@ -1914,10 +1914,10 @@ void DoRadiosityForTerrain() {
Light_surfaces[i * 2].elements = mem_rmalloc<rad_element>();
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<vector>(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<vector>(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<rad_element>();
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<vector>(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<vector>(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<vector>(3);
ASSERT(Light_surfaces[surf_index].verts != NULL);
Light_surfaces[surf_index].elements = mem_rmalloc<rad_element>();
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<vector>(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<vector>(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<float>(rp->num_faces);
ASSERT(Room_strongest_value[i][t]);
memset(Room_strongest_value[i][t], 0, sizeof(float) * rp->num_faces);
}

View File

@ -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<uint8_t>(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<uint8_t>(num_char);
for (i = 0; i < num_char; i++)
fnt.char_widths[i] = (uint8_t)READ_FONT_SHORT(ffin);
} else {

View File

@ -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<mngs_Pagelock>(8000);
ASSERT(already_read);
infile = (CFILE *)cfopen(TableLockFilename, "rb");

View File

@ -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<bsp_info>(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<int>(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<w_bank>(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<a_bank>(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<poly_wb_info>(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<w_bank>(pm->n_ground);
ASSERT(pm->ground_slots != nullptr);
for (i = 0; i < pm->n_ground; i++) {

View File

@ -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<music_ins>(MAX_MUSIC_INSTRUCTIONS);
m_str_buffer = (char *)mem_malloc(MAX_MUSIC_STRLEN);
m_ins_curptr = m_ins_buffer;
m_str_curptr = m_str_buffer;