From 4d2fdb231635130dda4020c1fd39b79fb0e4e79e Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Fri, 30 Aug 2024 20:52:36 +0200 Subject: [PATCH] mem_malloc type triviality checks (4/8) ``` git grep -l mem_malloc | xargs perl -i -lpe 's{\((\w+) \*\)mem_malloc\((\S+) \* sizeof\(\1\)\)}{mem_rmalloc<$1 *>($2)}' ``` --- Descent3/BOA.cpp | 16 ++++++++-------- Descent3/LoadLevel.cpp | 6 +++--- Descent3/audiotaunts.cpp | 2 +- Descent3/lightmap_info.cpp | 4 ++-- Descent3/object_lighting.cpp | 2 +- Descent3/pilot.cpp | 2 +- Descent3/render.cpp | 2 +- Descent3/special_face.cpp | 4 ++-- Descent3/vclip.cpp | 2 +- editor/EPath.cpp | 2 +- editor/Erooms.cpp | 10 +++++----- editor/MainFrm.cpp | 2 +- editor/Read3ds.cpp | 4 ++-- editor/ScriptLevelInterface.cpp | 16 ++++++++-------- editor/ScriptMassCompile.cpp | 2 +- editor/editor_lighting.cpp | 12 ++++++------ editor/editor_object_lighting.cpp | 4 ++-- editor/rad_init.cpp | 2 +- legacy/renderer/Direct3D.cpp | 10 +++++----- manage/manage.cpp | 6 +++--- model/polymodel.cpp | 18 +++++++++--------- sndlib/ddsoundload.cpp | 2 +- 22 files changed, 65 insertions(+), 65 deletions(-) diff --git a/Descent3/BOA.cpp b/Descent3/BOA.cpp index b590bc74..f2ff5074 100644 --- a/Descent3/BOA.cpp +++ b/Descent3/BOA.cpp @@ -2147,7 +2147,7 @@ void ComputeAABB(bool f_full) { if (BOA_AABB_ROOM_checksum[i] != 0 && BOA_AABB_ROOM_checksum[i] == computed_room_check[i]) continue; - r_struct_list[i] = (int16_t *)mem_malloc(Rooms[i].num_faces * sizeof(int16_t)); + r_struct_list[i] = mem_rmalloc(Rooms[i].num_faces); } } @@ -2318,8 +2318,8 @@ void ComputeAABB(bool f_full) { // // continue; - vector *s_max_xyz = (vector *)mem_malloc(num_structs_per_room[i] * sizeof(vector)); - vector *s_min_xyz = (vector *)mem_malloc(num_structs_per_room[i] * sizeof(vector)); + vector *s_max_xyz = mem_rmalloc(num_structs_per_room[i]); + vector *s_min_xyz = mem_rmalloc(num_structs_per_room[i]); for (count = 0; count < num_structs_per_room[i]; count++) { @@ -2412,12 +2412,12 @@ void ComputeAABB(bool f_full) { rp->num_bbf_regions = 27 + num_structs_per_room[i] - 1; rp->bbf_list = (int16_t **)mem_malloc(MAX_REGIONS_PER_ROOM * sizeof(int16_t *)); for (x = 0; x < MAX_REGIONS_PER_ROOM; x++) { - rp->bbf_list[x] = (int16_t *)mem_malloc(rp->num_faces * sizeof(int16_t)); + rp->bbf_list[x] = mem_rmalloc(rp->num_faces); } - rp->num_bbf = (int16_t *)mem_malloc(MAX_REGIONS_PER_ROOM * sizeof(int16_t)); - rp->bbf_list_min_xyz = (vector *)mem_malloc(MAX_REGIONS_PER_ROOM * sizeof(vector)); - rp->bbf_list_max_xyz = (vector *)mem_malloc(MAX_REGIONS_PER_ROOM * sizeof(vector)); - rp->bbf_list_sector = (uint8_t *)mem_malloc(MAX_REGIONS_PER_ROOM * sizeof(uint8_t)); + rp->num_bbf = mem_rmalloc(MAX_REGIONS_PER_ROOM); + rp->bbf_list_min_xyz = mem_rmalloc(MAX_REGIONS_PER_ROOM); + rp->bbf_list_max_xyz = mem_rmalloc(MAX_REGIONS_PER_ROOM); + rp->bbf_list_sector = mem_rmalloc(MAX_REGIONS_PER_ROOM); for (x = 0; x < 27; x++) { rp->bbf_list_sector[x] = bbf_lookup[x]; diff --git a/Descent3/LoadLevel.cpp b/Descent3/LoadLevel.cpp index c6fadbd4..b67582a3 100644 --- a/Descent3/LoadLevel.cpp +++ b/Descent3/LoadLevel.cpp @@ -2661,7 +2661,7 @@ void ReadNewLightmapChunk(CFILE *fp, int version) { return; } - uint16_t *lightmap_remap = (uint16_t *)mem_malloc(MAX_LIGHTMAPS * sizeof(uint16_t)); + uint16_t *lightmap_remap = mem_rmalloc(MAX_LIGHTMAPS); nummaps = cf_ReadInt(fp); @@ -2897,7 +2897,7 @@ void ReadGamePathsChunk(CFILE *fp, int version) { for (i = 0; i < Num_game_paths; i++) { GamePaths[i].used = 1; GamePaths[i].name[0] = 0; - GamePaths[i].pathnodes = (node *)mem_malloc(MAX_NODES_PER_PATH * sizeof(node)); + GamePaths[i].pathnodes = mem_rmalloc(MAX_NODES_PER_PATH); GamePaths[i].flags = 0; // Read in the path's info @@ -4884,7 +4884,7 @@ void WriteLightmapChunk(CFILE *fp) { int lightmap_info_count = 0; int lightmap_count = 0; - uint16_t *lightmap_remap = (uint16_t *)mem_malloc(MAX_LIGHTMAPS * sizeof(uint16_t)); + uint16_t *lightmap_remap = mem_rmalloc(MAX_LIGHTMAPS); uint8_t *lightmap_spoken_for = (uint8_t *)mem_malloc(MAX_LIGHTMAPS); ASSERT(lightmap_remap); diff --git a/Descent3/audiotaunts.cpp b/Descent3/audiotaunts.cpp index 1238706c..4e5b21e2 100644 --- a/Descent3/audiotaunts.cpp +++ b/Descent3/audiotaunts.cpp @@ -756,7 +756,7 @@ char taunt_LoadWaveFile(const char *filename, tWaveFile *wave) { if (wave->sample_16bit == NULL) { ASSERT(wave->sample_8bit); - wave->sample_16bit = (int16_t *)mem_malloc(wave->sample_length * sizeof(int16_t)); + wave->sample_16bit = mem_rmalloc(wave->sample_length); // NOTE: Interesting note on sound conversion: 16 bit sounds are signed (0 biase). 8 bit sounds are unsigned // (+128 biase). diff --git a/Descent3/lightmap_info.cpp b/Descent3/lightmap_info.cpp index 6f8703af..2891cdb8 100644 --- a/Descent3/lightmap_info.cpp +++ b/Descent3/lightmap_info.cpp @@ -56,9 +56,9 @@ void InitLightmapInfo(int nummaps) { return; if (nummaps == 0) { - LightmapInfo = (lightmap_info *)mem_malloc(MAX_LIGHTMAP_INFOS * sizeof(lightmap_info)); + LightmapInfo = mem_rmalloc(MAX_LIGHTMAP_INFOS); ASSERT(LightmapInfo); - Free_lmi_list = (uint16_t *)mem_malloc(MAX_LIGHTMAP_INFOS * sizeof(uint16_t)); + Free_lmi_list = mem_rmalloc(MAX_LIGHTMAP_INFOS); ASSERT(Free_lmi_list); for (i = 0; i < MAX_LIGHTMAP_INFOS; i++) { diff --git a/Descent3/object_lighting.cpp b/Descent3/object_lighting.cpp index 104703bd..8b808483 100644 --- a/Descent3/object_lighting.cpp +++ b/Descent3/object_lighting.cpp @@ -540,7 +540,7 @@ void SetupObjectLightmapMemory(object *obj) { obj->lm_object.num_faces[Mnum] = pm->submodel[Mnum].num_faces; obj->lm_object.lightmap_faces[Mnum] = - (lightmap_object_face *)mem_malloc(obj->lm_object.num_faces[Mnum] * sizeof(lightmap_object_face)); + mem_rmalloc(obj->lm_object.num_faces[Mnum]); ASSERT(obj->lm_object.lightmap_faces[Mnum]); for (Fnum = 0; Fnum < pm->submodel[Mnum].num_faces; Fnum++) { diff --git a/Descent3/pilot.cpp b/Descent3/pilot.cpp index d86d5388..d46e026a 100644 --- a/Descent3/pilot.cpp +++ b/Descent3/pilot.cpp @@ -3165,7 +3165,7 @@ void ShowPilotPicDialog(pilot *Pilot) { // Initialize PPicDlgInfo data // --------------------------- uint16_t *id_list; - id_list = (uint16_t *)mem_malloc(num_pilots * sizeof(uint16_t)); + id_list = mem_rmalloc(num_pilots); if (!id_list) { // out of memory diff --git a/Descent3/render.cpp b/Descent3/render.cpp index e9dfb898..43071b6e 100644 --- a/Descent3/render.cpp +++ b/Descent3/render.cpp @@ -3658,7 +3658,7 @@ void ConsolidateMineMirrors() { rp->mirror_face = 0; continue; } - rp->mirror_faces_list = (uint16_t *)mem_malloc(num_mirror_faces * sizeof(uint16_t)); + rp->mirror_faces_list = mem_rmalloc(num_mirror_faces); ASSERT(rp->mirror_faces_list); rp->num_mirror_faces = num_mirror_faces; // Now go through and fill in our list diff --git a/Descent3/special_face.cpp b/Descent3/special_face.cpp index fffe8e3b..e3117b13 100644 --- a/Descent3/special_face.cpp +++ b/Descent3/special_face.cpp @@ -56,7 +56,7 @@ int AllocSpecialFace(int type, int num, bool vertnorms, int num_vertnorms) { memset(&SpecialFaces[n], 0, sizeof(special_face)); - SpecialFaces[n].spec_instance = (specular_instance *)mem_malloc(num * sizeof(specular_instance)); + SpecialFaces[n].spec_instance = mem_rmalloc(num); ASSERT(SpecialFaces[n].spec_instance); SpecialFaces[n].type = type; @@ -65,7 +65,7 @@ int AllocSpecialFace(int type, int num, bool vertnorms, int num_vertnorms) { SpecialFaces[n].used = 1; if (vertnorms) { - SpecialFaces[n].vertnorms = (vector *)mem_malloc(num_vertnorms * sizeof(vector)); + SpecialFaces[n].vertnorms = mem_rmalloc(num_vertnorms); ASSERT(SpecialFaces[n].vertnorms); SpecialFaces[n].flags |= SFF_SPEC_SMOOTH; } diff --git a/Descent3/vclip.cpp b/Descent3/vclip.cpp index 478a8eea..d06c1d01 100644 --- a/Descent3/vclip.cpp +++ b/Descent3/vclip.cpp @@ -204,7 +204,7 @@ int AllocVClip() { for (i = 0; i < MAX_VCLIPS; i++) { if (GameVClips[i].used == 0) { memset(&GameVClips[i], 0, sizeof(vclip)); - GameVClips[i].frames = (int16_t *)mem_malloc(VCLIP_MAX_FRAMES * sizeof(int16_t)); + GameVClips[i].frames = mem_rmalloc(VCLIP_MAX_FRAMES); ASSERT(GameVClips[i].frames); GameVClips[i].frame_time = DEFAULT_FRAMETIME; GameVClips[i].flags = VCF_NOT_RESIDENT; diff --git a/editor/EPath.cpp b/editor/EPath.cpp index fbda8e8d..c128247a 100644 --- a/editor/EPath.cpp +++ b/editor/EPath.cpp @@ -101,7 +101,7 @@ int AllocGamePath() { GamePaths[i].num_nodes = 0; GamePaths[i].flags = 0; - GamePaths[i].pathnodes = (node *)mem_malloc(MAX_NODES_PER_PATH * sizeof(node)); + GamePaths[i].pathnodes = mem_rmalloc(MAX_NODES_PER_PATH); mprintf(0, "Path %d got some\n", i); Num_game_paths++; diff --git a/editor/Erooms.cpp b/editor/Erooms.cpp index bf70e461..8fe8f980 100644 --- a/editor/Erooms.cpp +++ b/editor/Erooms.cpp @@ -1239,7 +1239,7 @@ void FixConcaveFaces(room *rp, int *facelist, int facecount) { // Allocate memory for our new faces int nfaces = rp->num_faces + num_new_faces; - newfaces = (face *)mem_malloc(nfaces * sizeof(face)); + newfaces = mem_rmalloc(nfaces); ASSERT(newfaces != NULL); // Copy all the faces into our new array @@ -1248,9 +1248,9 @@ void FixConcaveFaces(room *rp, int *facelist, int facecount) { if (t != facelist[i]) { int nverts = rp->faces[t].num_verts; - newfaces[t].face_verts = (int16_t *)mem_malloc(nverts * sizeof(int16_t)); + newfaces[t].face_verts = mem_rmalloc(nverts); ASSERT(newfaces[t].face_verts != NULL); - newfaces[t].face_uvls = (roomUVL *)mem_malloc(nverts * sizeof(roomUVL)); + newfaces[t].face_uvls = mem_rmalloc(nverts); ASSERT(newfaces[t].face_uvls != NULL); newfaces[t].normal = rp->faces[t].normal; @@ -1268,9 +1268,9 @@ void FixConcaveFaces(room *rp, int *facelist, int facecount) { { int nverts = 3; - newfaces[t].face_verts = (int16_t *)mem_malloc(nverts * sizeof(int16_t)); + newfaces[t].face_verts = mem_rmalloc(nverts); ASSERT(newfaces[t].face_verts != NULL); - newfaces[t].face_uvls = (roomUVL *)mem_malloc(nverts * sizeof(roomUVL)); + newfaces[t].face_uvls = mem_rmalloc(nverts); ASSERT(newfaces[t].face_uvls != NULL); newfaces[t].tmap = rp->faces[t].tmap; diff --git a/editor/MainFrm.cpp b/editor/MainFrm.cpp index 786ce586..e8b994f8 100644 --- a/editor/MainFrm.cpp +++ b/editor/MainFrm.cpp @@ -3456,7 +3456,7 @@ void CMainFrame::OnShowAllCheckedOut() { char text_buf[10000], *t; // Get all locked pages - mngs_Pagelock *LockList = (mngs_Pagelock *)mem_malloc(MAX_LOCKLIST_ELEMENTS * sizeof(mngs_Pagelock)); + mngs_Pagelock *LockList = mem_rmalloc(MAX_LOCKLIST_ELEMENTS); int n = mng_GetListOfLocks(LockList, MAX_LOCKLIST_ELEMENTS, NULL); // ASSERT(n >= 1); //always dummy page? diff --git a/editor/Read3ds.cpp b/editor/Read3ds.cpp index 70beb8a1..7ddacd59 100644 --- a/editor/Read3ds.cpp +++ b/editor/Read3ds.cpp @@ -204,8 +204,8 @@ int Read3DSMaxFile(char *filename) { Nest_level = 0; // Alloc space for reading stuff in - Reading_room.faces = (reading_face *)mem_malloc(MAX_READING_ROOM_FACES * sizeof(reading_face)); - Reading_room.verts = (vector *)mem_malloc(MAX_VERTS_PER_ROOM * sizeof(vector)); + Reading_room.faces = mem_rmalloc(MAX_READING_ROOM_FACES); + Reading_room.verts = mem_rmalloc(MAX_VERTS_PER_ROOM); Reading_room.num_faces = 0; Reading_room.num_verts = 0; diff --git a/editor/ScriptLevelInterface.cpp b/editor/ScriptLevelInterface.cpp index 2e3d52ea..ef7714c8 100644 --- a/editor/ScriptLevelInterface.cpp +++ b/editor/ScriptLevelInterface.cpp @@ -1249,7 +1249,7 @@ bool CScriptLevelInterface::DeleteLevel() { if (list_size == 0) return false; - int *index_map = (int *)mem_malloc(list_size * sizeof(int)); + int *index_map = mem_rmalloc(list_size); if (!index_map) return false; @@ -1394,7 +1394,7 @@ bool CScriptLevelInterface::DeleteScript() { if (list_size == 0) return false; - int *index_map = (int *)mem_malloc(list_size * sizeof(int)); + int *index_map = mem_rmalloc(list_size); if (!index_map) return false; @@ -1511,7 +1511,7 @@ bool CScriptLevelInterface::CheckInScripts() { if (list_size == 0) return false; - int *index_map = (int *)mem_malloc(list_size * sizeof(int)); + int *index_map = mem_rmalloc(list_size); if (!index_map) return false; @@ -1619,7 +1619,7 @@ bool CScriptLevelInterface::CheckInLevels() { if (list_size == 0) return false; - int *index_map = (int *)mem_malloc(list_size * sizeof(int)); + int *index_map = mem_rmalloc(list_size); if (!index_map) return false; @@ -1759,7 +1759,7 @@ bool CScriptLevelInterface::CheckOutScripts() { if (list_size == 0) return false; - int *index_map = (int *)mem_malloc(list_size * sizeof(int)); + int *index_map = mem_rmalloc(list_size); if (!index_map) return false; @@ -1871,7 +1871,7 @@ bool CScriptLevelInterface::CheckOutLevels() { if (list_size == 0) return false; - int *index_map = (int *)mem_malloc(list_size * sizeof(int)); + int *index_map = mem_rmalloc(list_size); if (!index_map) return false; @@ -2015,7 +2015,7 @@ bool CScriptLevelInterface::UndoCheckOutScripts() { if (list_size == 0) return false; - int *index_map = (int *)mem_malloc(list_size * sizeof(int)); + int *index_map = mem_rmalloc(list_size); if (!index_map) return false; @@ -2126,7 +2126,7 @@ bool CScriptLevelInterface::UndoCheckOutLevels() { if (list_size == 0) return false; - int *index_map = (int *)mem_malloc(list_size * sizeof(int)); + int *index_map = mem_rmalloc(list_size); if (!index_map) return false; diff --git a/editor/ScriptMassCompile.cpp b/editor/ScriptMassCompile.cpp index c947a574..843c5980 100644 --- a/editor/ScriptMassCompile.cpp +++ b/editor/ScriptMassCompile.cpp @@ -145,7 +145,7 @@ void CScriptMassCompile::OnBuild() { if (list_size == 0) return; - index_map = (int *)mem_malloc(list_size * sizeof(int)); + index_map = mem_rmalloc(list_size); if (!index_map) return; diff --git a/editor/editor_lighting.cpp b/editor/editor_lighting.cpp index f3b0f7a0..50589366 100644 --- a/editor/editor_lighting.cpp +++ b/editor/editor_lighting.cpp @@ -952,7 +952,7 @@ void DoRadiosityForRooms() { // Allocate enough memory to hold all surfaces - Light_surfaces = (rad_surface *)mem_malloc(facecount * sizeof(rad_surface)); + Light_surfaces = mem_rmalloc(facecount); ASSERT(Light_surfaces != NULL); // Set initial surface properties @@ -968,7 +968,7 @@ void DoRadiosityForRooms() { ComputeSurfaceRes(&Light_surfaces[surface_index], &Rooms[i], t); if (Rooms[i].faces[t].num_verts) { - Light_surfaces[surface_index].verts = (vector *)mem_malloc(Rooms[i].faces[t].num_verts * sizeof(vector)); + Light_surfaces[surface_index].verts = mem_rmalloc(Rooms[i].faces[t].num_verts); ASSERT(Light_surfaces[surface_index].verts != NULL); } else { Light_surfaces[surface_index].verts = NULL; @@ -1205,7 +1205,7 @@ void DoRadiosityForCurrentRoom(room *rp) { // Allocate enough memory to hold all surfaces - Light_surfaces = (rad_surface *)mem_malloc(facecount * sizeof(rad_surface)); + Light_surfaces = mem_rmalloc(facecount); ASSERT(Light_surfaces != NULL); // Set initial surface properties @@ -1215,7 +1215,7 @@ void DoRadiosityForCurrentRoom(room *rp) { ComputeSurfaceRes(&Light_surfaces[surface_index], rp, t); if (rp->faces[t].num_verts) { - Light_surfaces[surface_index].verts = (vector *)mem_malloc(rp->faces[t].num_verts * sizeof(vector)); + Light_surfaces[surface_index].verts = mem_rmalloc(rp->faces[t].num_verts); ASSERT(Light_surfaces[surface_index].verts != NULL); } else { Light_surfaces[surface_index].verts = NULL; @@ -1877,7 +1877,7 @@ void DoRadiosityForTerrain() { terrain_sums[1] = (spectra *)mem_malloc(TERRAIN_WIDTH * TERRAIN_DEPTH * sizeof(spectra)); ASSERT(terrain_sums[0] && terrain_sums[1]); - Light_surfaces = (rad_surface *)mem_malloc(total_surfaces * sizeof(rad_surface)); + Light_surfaces = mem_rmalloc(total_surfaces); ASSERT(Light_surfaces != NULL); // Setup radiosity surfaces @@ -2041,7 +2041,7 @@ void DoRadiosityForTerrain() { ComputeSurfaceRes(&Light_surfaces[surf_index], &Rooms[i], t); - Light_surfaces[surf_index].verts = (vector *)mem_malloc(Rooms[i].faces[t].num_verts * sizeof(vector)); + Light_surfaces[surf_index].verts = mem_rmalloc(Rooms[i].faces[t].num_verts); ASSERT(Light_surfaces[surf_index].verts != NULL); Light_surfaces[surf_index].elements = (rad_element *)mem_malloc( diff --git a/editor/editor_object_lighting.cpp b/editor/editor_object_lighting.cpp index 5708c7b8..50f1b4d3 100644 --- a/editor/editor_object_lighting.cpp +++ b/editor/editor_object_lighting.cpp @@ -314,7 +314,7 @@ int ComputeSurfacesForObjects(int surface_index, int terrain) { ComputeObjectSurfaceRes(&Light_surfaces[surface_index], &Objects[i], t, j); if (sm->faces[j].nverts > 0) { - Light_surfaces[surface_index].verts = (vector *)mem_malloc(sm->faces[j].nverts * sizeof(vector)); + Light_surfaces[surface_index].verts = mem_rmalloc(sm->faces[j].nverts); ASSERT(Light_surfaces[surface_index].verts != NULL); } else Light_surfaces[surface_index].verts = NULL; @@ -400,7 +400,7 @@ int ComputeSurfacesForObjectsForSingleRoom(int surface_index, int roomnum) { ComputeObjectSurfaceRes(&Light_surfaces[surface_index], &Objects[i], t, j); if (sm->faces[j].nverts > 0) { - Light_surfaces[surface_index].verts = (vector *)mem_malloc(sm->faces[j].nverts * sizeof(vector)); + Light_surfaces[surface_index].verts = mem_rmalloc(sm->faces[j].nverts); ASSERT(Light_surfaces[surface_index].verts != NULL); } else Light_surfaces[surface_index].verts = NULL; diff --git a/editor/rad_init.cpp b/editor/rad_init.cpp index add423c4..42e69268 100644 --- a/editor/rad_init.cpp +++ b/editor/rad_init.cpp @@ -125,7 +125,7 @@ void InitRadiosityRun() { void SetupFormFactors() { ASSERT(rad_NumElements > 0); - rad_FormFactors = (float *)mem_malloc(rad_NumElements * sizeof(float)); + rad_FormFactors = mem_rmalloc(rad_NumElements); ASSERT(rad_FormFactors != NULL); } diff --git a/legacy/renderer/Direct3D.cpp b/legacy/renderer/Direct3D.cpp index 956ec0d0..e092090f 100644 --- a/legacy/renderer/Direct3D.cpp +++ b/legacy/renderer/Direct3D.cpp @@ -1021,7 +1021,7 @@ int d3d_TextureCacheInit() { } // Allocate room to hold all our surfaces - UploadSurfaces = (LPDIRECTDRAWSURFACE4 *)mem_malloc(NUM_TEXTURE_CLASSES * sizeof(LPDIRECTDRAWSURFACE4)); + UploadSurfaces = mem_rmalloc(NUM_TEXTURE_CLASSES); if (UploadSurfaces == NULL) { mprintf(0, "Couldn't allocate memory for UploadSurfaces!\n"); @@ -1030,7 +1030,7 @@ int d3d_TextureCacheInit() { } // Allocate room to hold all our 4444 surfaces - Upload4444Surfaces = (LPDIRECTDRAWSURFACE4 *)mem_malloc(NUM_TEXTURE_CLASSES * sizeof(LPDIRECTDRAWSURFACE4)); + Upload4444Surfaces = mem_rmalloc(NUM_TEXTURE_CLASSES); if (Upload4444Surfaces == NULL) { mprintf(0, "Couldn't allocate memory for Upload4444Surfaces!\n"); @@ -1038,7 +1038,7 @@ int d3d_TextureCacheInit() { return 0; } - BitmapTextureSurfaces = (LPDIRECTDRAWSURFACE4 *)mem_malloc(MAX_BITMAPS * sizeof(LPDIRECTDRAWSURFACE4)); + BitmapTextureSurfaces = mem_rmalloc(MAX_BITMAPS); if (BitmapTextureSurfaces == NULL) { mprintf(0, "Couldn't allocate memory for BitmapTextureSurfaces!\n"); @@ -1047,7 +1047,7 @@ int d3d_TextureCacheInit() { } // Allocate room to hold all our surfaces - LightmapTextureSurfaces = (LPDIRECTDRAWSURFACE4 *)mem_malloc(MAX_LIGHTMAPS * sizeof(LPDIRECTDRAWSURFACE4)); + LightmapTextureSurfaces = mem_rmalloc(MAX_LIGHTMAPS); if (LightmapTextureSurfaces == NULL) { mprintf(0, "Couldn't allocate memory for LightmapTextureSurfaces!\n"); rend_SetErrorMessage("Couldn't alloc mem for LightmapTextureSurfaces!"); @@ -1055,7 +1055,7 @@ int d3d_TextureCacheInit() { } if (d3d_CanBumpmap) { - BumpmapTextureSurfaces = (LPDIRECTDRAWSURFACE4 *)mem_malloc(MAX_BUMPMAPS * sizeof(LPDIRECTDRAWSURFACE4)); + BumpmapTextureSurfaces = mem_rmalloc(MAX_BUMPMAPS); if (BumpmapTextureSurfaces == NULL) { mprintf(0, "Couldn't allocate memory for BumpmapTextureSurfaces!\n"); rend_SetErrorMessage("Couldn't alloc mem for BumpmapTextureSurfaces!"); diff --git a/manage/manage.cpp b/manage/manage.cpp index f3e9423f..fc0d25d0 100644 --- a/manage/manage.cpp +++ b/manage/manage.cpp @@ -629,9 +629,9 @@ int mng_InitTableFiles() { // Loads our tables int mng_LoadTableFiles(int show_progress) { if (Network_up) { - LockList = (mngs_Pagelock *)mem_malloc(MAX_LOCKLIST_ELEMENTS * sizeof(mngs_Pagelock)); + LockList = mem_rmalloc(MAX_LOCKLIST_ELEMENTS); Num_locklist = mng_GetListOfLocks(LockList, MAX_LOCKLIST_ELEMENTS, TableUser); - OldFiles = (old_file *)mem_malloc(MAX_OLDFILE_ELEMENTS * sizeof(old_file)); + OldFiles = mem_rmalloc(MAX_OLDFILE_ELEMENTS); Num_old_files = 0; ASSERT(OldFiles); #if defined(WIN32) @@ -2735,7 +2735,7 @@ bool mng_SetAddonTable(char *name) { strcpy(AddOnDataTables[Num_addon_tables].AddOnTableFilename, name); AddOnDataTables[Num_addon_tables].Addon_tracklocks = - (mngs_track_lock *)mem_malloc(MAX_ADDON_TRACKLOCKS * sizeof(mngs_track_lock)); + mem_rmalloc(MAX_ADDON_TRACKLOCKS); AddOnDataTables[Num_addon_tables].Num_addon_tracklocks = 0; ASSERT(AddOnDataTables[Num_addon_tables].Addon_tracklocks); memset(AddOnDataTables[Num_addon_tables].Addon_tracklocks, 0, MAX_ADDON_TRACKLOCKS * sizeof(mngs_track_lock)); diff --git a/model/polymodel.cpp b/model/polymodel.cpp index 0247fa50..9a56642a 100644 --- a/model/polymodel.cpp +++ b/model/polymodel.cpp @@ -1419,9 +1419,9 @@ int ReadNewModelFile(int polynum, CFILE *infile) { ASSERT(nverts < MAX_POLYGON_VECS); if (nverts) { - pm->submodel[n].verts = (vector *)mem_malloc(nverts * sizeof(vector)); - pm->submodel[n].vertnorms = (vector *)mem_malloc(nverts * sizeof(vector)); - pm->submodel[n].alpha = (float *)mem_malloc(nverts * sizeof(float)); + pm->submodel[n].verts = mem_rmalloc(nverts); + pm->submodel[n].vertnorms = mem_rmalloc(nverts); + pm->submodel[n].alpha = mem_rmalloc(nverts); ASSERT(pm->submodel[n].verts); ASSERT(pm->submodel[n].vertnorms); ASSERT(pm->submodel[n].alpha); @@ -1474,9 +1474,9 @@ int ReadNewModelFile(int polynum, CFILE *infile) { pm->submodel[n].num_faces = nfaces; if (nfaces) { - pm->submodel[n].faces = (polyface *)mem_malloc(nfaces * sizeof(polyface)); - pm->submodel[n].face_min = (vector *)mem_malloc(nfaces * sizeof(vector)); - pm->submodel[n].face_max = (vector *)mem_malloc(nfaces * sizeof(vector)); + pm->submodel[n].faces = mem_rmalloc(nfaces); + pm->submodel[n].face_min = mem_rmalloc(nfaces); + pm->submodel[n].face_max = mem_rmalloc(nfaces); ASSERT(pm->submodel[n].faces); } else { pm->submodel[n].faces = nullptr; @@ -1524,13 +1524,13 @@ int ReadNewModelFile(int polynum, CFILE *infile) { // Allocate our space if (current_count) { - sm->vertnum_memory = (int16_t *)mem_malloc(current_count * sizeof(int16_t)); + sm->vertnum_memory = mem_rmalloc(current_count); ASSERT(sm->vertnum_memory); - sm->u_memory = (float *)mem_malloc(current_count * sizeof(float)); + sm->u_memory = mem_rmalloc(current_count); ASSERT(sm->u_memory); - sm->v_memory = (float *)mem_malloc(current_count * sizeof(float)); + sm->v_memory = mem_rmalloc(current_count); ASSERT(sm->v_memory); } else { sm->vertnum_memory = nullptr; diff --git a/sndlib/ddsoundload.cpp b/sndlib/ddsoundload.cpp index 29b20444..31d5aa68 100644 --- a/sndlib/ddsoundload.cpp +++ b/sndlib/ddsoundload.cpp @@ -457,7 +457,7 @@ char SoundLoadWaveFile(const char *filename, float percent_volume, int sound_fil } else if (SoundFiles[sound_file_index].sample_16bit == NULL && f_high_quality) { SoundFiles[sound_file_index].sample_16bit = - (int16_t *)mem_malloc(SoundFiles[sound_file_index].sample_length * sizeof(int16_t)); + mem_rmalloc(SoundFiles[sound_file_index].sample_length); // NOTE: Interesting note on sound conversion: 16 bit sounds are signed (0 biase). 8 bit sounds are unsigned // (+128 biase).